Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 54 lines (40 sloc) 0.915 kb
/* Copyright 2008 - Sleepless Software Inc. - All Rights Reserved */
#ifndef com_sleepless_misc_exception_h
#define com_sleepless_misc_exception_h
/*
This struct/class can be use for "throwing".
It uses varargs so that you can specify a format string
and args in it's constructor and have it carry the
resulting formatted string as it's message payload.
For example:
try
{
if(x != 0)
{
throw new Exception("x is %d ... expected 0", x);
}
}
catch(Exception *e)
{
printf("OUCH: %s\n", e->text);
}
*/
#include <stdarg.h>
#include <stdio.h>
#define EXCEPT(exctype) \
struct exctype \
{ \
char text[1000]; \
exctype(const char *fmt, ...) \
{ \
va_list marker; \
va_start(marker, fmt); \
vsprintf(text, fmt, marker); \
va_end(marker); \
} \
}
EXCEPT(Failure);
EXCEPT(Error);
EXCEPT(Anomaly);
EXCEPT(Quirk);
#endif // com_sleepless_misc_exception_h
Jump to Line
Something went wrong with that request. Please try again.