libexcept
Macros | Typedefs | Functions | Variables
libexcept

Macros

#define exception_new(type, data)   __exception_new(&(type), (data), __FILE__, __LINE__)
#define except_raise(type, data)   except_throw(exception_new((type), (data)))
#define except_assert(condition)   __except_assert((condition), __FILE__, __LINE__)

Typedefs

typedef struct _ExceptionType ExceptionType
typedef struct _Exception Exception

Functions

ExceptionTypeexception_get_type (Exception *exception)
void exception_free (Exception *exception)
void * exception_get_data (Exception *exception)
char * exception_get_file (Exception *exception)
int exception_get_line (Exception *exception)
void except_throw (Exception *exception)

Variables

ExceptionType BaseException
ExceptionType AssertException

Detailed Description

Macro Definition Documentation

#define except_assert (   condition)    __except_assert((condition), __FILE__, __LINE__)

Checks a given condition, throwing an exception if it is not met. The exception thrown is of type AssertException.

Parameters
conditionThe condition to test. If this evaluates to zero (false), an exception is thrown.
#define except_raise (   type,
  data 
)    except_throw(exception_new((type), (data)))

Raise a new exception. This is equivalent to:

Parameters
typeThe type of exception to raise.
dataExtra data to include with the exception.
#define exception_new (   type,
  data 
)    __exception_new(&(type), (data), __FILE__, __LINE__)

Create a new exception.

Parameters
typeThe type of exception to create.
dataA pointer to some extra data to include with the exception.
Returns
A new exception object.

Typedef Documentation

typedef struct _Exception Exception

An exception. Created using exception_new.

See Also
exception_new
typedef struct _ExceptionType ExceptionType

A type of exception. New exception types should be defined by assigning an ExceptionType variable using the EXCEPTION_TYPE macro. For example:

ExceptionType AppleException = EXCEPTION_TYPE(BaseException);
ExceptionType OrangeException = EXCEPTION_TYPE(BaseException);
ExceptionType SatsumaException = EXCEPTION_TYPE(OrangeException);
See Also
BaseException

Function Documentation

void except_throw ( Exception exception)

Throw an exception. This function does not return.

Parameters
exceptionThe exception to throw.
See Also
except_raise
void exception_free ( Exception exception)

Free an exception. You should almost never need to call this, as when an exception is caught in an except_catch block, the exception is freed automatically.

Parameters
exceptionThe exception to free.
void* exception_get_data ( Exception exception)

Returns a pointer to extra user-specified data included with an exception. This data is specified when the user creates the exception (see exception_new).

Parameters
exceptionThe exception.
Returns
The user-specified data.
See Also
exception_new
char* exception_get_file ( Exception exception)

Returns the name of the source file in which an exception was created.

Parameters
exceptionThe exception.
Returns
A C string containing the name of the source file in which the exception was created.
See Also
exception_get_line
int exception_get_line ( Exception exception)

Returns the line number within the source file where an exception was created.

Parameters
exceptionThe exception.
Returns
The line number of the line where the exception occurred.
See Also
exception_get_file
ExceptionType* exception_get_type ( Exception exception)

Returns the type of an exception. This is the type specified to exception_new.

Parameters
exceptionThe exception.
Returns
The type of the exception.
See Also
exception_new
ExceptionType

Variable Documentation

ExceptionType AssertException

Exception type thrown when using except_assert.

ExceptionType BaseException

The root of all exception types.