LException

Description Exception handling
Header file LException.h
Author Camil Demetrescu
Created Jan 11, 2003
Last updated Sep 27, 2003

 

Contents


Introduction

Component LException defines macros for supporting in C the Try ... Throw ... Catch exception handling mechanism typical of C++/Java.


Interface

Constants

LException_ID

Types

LException

Macros

Try
Throw(ui4 inExceptionCode)
Catch(LException* inCaughtException)
CatchAny
Rethrow

Functions

i1*  LException_GetName     (LException* inException)
ui4  LException_GetCode     (LException* inException)
ui4  LException_GetLine     (LException* inException)
i1*  LException_GetFileName (LException* inException)
void LException_Dump        (LException* inException)


API Reference

Macro Arguments Description
Try - Like try in C++/Java. Important notice: NEVER use return, break, continue, goto to jump out of a Try { ... } block. This will corrupt immediately the execution environment, causing the program to crash.
Throw ui4 inExceptionCode Like throw in C++/Java. Raises an exception with code inExceptionCode.
Catch LException* inException Like catch in C++/Java. Argument inException is assigned with the address of the thrown exception. Differently from C++, only one catch block is allowed. Notice: objects of type LException do not need to be deallocated explicitly.
CatchAny - Like Catch, but it does not require to specify an argument.
Rethrow -

Used in a Catch (or CatchAny) block to rethrow the exception exactly as it was caught. It is useful in a CatchAny block where the pointer to the thrown exception is unknown. Differently from Throw, it does not generate a new exception, but it rethrows an exception that was just caught.

Function Arguments Description Returns Throws
GetName LException* inException Returns the exception name stored in object inException: e.g., if exception inException is thrown with Throw(LDebug_INTERNAL_ERROR), then GetName returns a pointer to the C string "LDebug_INTERNAL_ERROR".

i1*

Exception name

-
GetCode LException* inException Returns the exception code stored in object inException: e.g., if exception inException is thrown with Throw(LDebug_INTERNAL_ERROR), then GetCode returns the integer value LDebug_INTERNAL_ERROR.

ui4

Exception code

 
GetFileName LException* inException Accesses the line number in the source file where object inException was created via Throw : e.g., if exception inException is thrown at line 233, then GetFileName returns 233.

i1*

Line number in source code where exception was generated

-
GetFileName LException* inException Accesses the name of the source file where object inException was created via Throw : e.g., if exception inException is thrown in file LMemory.c, then GetFileName returns a pointer to the C string "LMemory.c".

i1*

File name of source code where exception was generated

-
Dump LException* inException Sends information about exception inException to the message console. - -


Example

...
theBlock = NULL;
Try {
    if (theSize>255) Throw(LDebug_INTERNAL_ERROR);
theBlock = LMemory_Malloc(theSize); ... LMemory_Free(&theBlock); } CatchAny { /* cleanup */ if (theBlock!=NULL) LMemory_Free(&theBlock); Rethrow; }

Revision history