![]() |
ooc
1.3c
Object Oriented tollkit fo ANSI C
|
Exception class - a standard ooc error reporting class. More...
#include "ooc.h"
Macros | |
#define | end_try |
Closing mark for the try catch construct. More... | |
Exception handling. | |
#define | try |
Opens a try ... More... | |
#define | catch(ec) |
Catches an exception of a given class. More... | |
#define | catch_any |
Catches any thrown Exceptions. More... | |
#define | finally |
Finally block. More... | |
Managed pointers, managed Objects | |
Using managed pointers you will not get the program control in case of an exception, but it is guaranteed, that the memory is freed or the Object is deleted in case of an exception. (You may consider this as analogie for
| |
#define | ooc_manage(p_target, p_destroyer) |
Manage a pointer. More... | |
#define | ooc_manage_object(p_target) |
Manage an Object. More... | |
#define | ooc_pass(target) |
Removes the most recently pushed pointer from the managed pointers' stack. More... | |
Typedefs | |
typedef struct ExceptionObject * | Exception |
Exception class declaration. | |
Enumerations | |
enum | error_codes { err_no_error = 0, err_out_of_memory, err_bad_throw, err_bad_cast, err_undefined_virtual, err_uninitialized, err_can_not_be_duplicated, err_wrong_position, err_bad_connect, err_already_in_use, err_interface_not_implemented, err_user_code = ~0 } |
Error codes. More... | |
Functions | |
Exception | exception_new (enum error_codes error) |
Creates a new ooc system Exception. More... | |
int | exception_get_error_code (const Exception exception) |
Gets the ooc core error code. More... | |
int | exception_get_user_code (const Exception exception) |
Gets the user error code. More... | |
void | ooc_throw (Exception exception) |
Throws an exception. More... | |
void | ooc_rethrow (void) |
Retrhows a caught exception. More... | |
Exception class - a standard ooc error reporting class.
Exception class is used to throw exceptions either by the ooc core, or by the user of the ooc as well. Exception should be used as a base class for the User defined exception classes. Exceptions can be caught by class types, so if you would like to distinguish the caught exceptions, always use a derived class! The usual way of throwing an excetption is:
The recommended way of using your own exception class is:
#define catch | ( | ec | ) |
Catches an exception of a given class.
It must include exactly one statement, or group of statements in curly braces.
ec | The name of the exception class to be caought. Must be a subclass of Exception. |
exception
variable of Exception type can be used as the caught object. You must not delete the exception
Object! #define catch_any |
Catches any thrown Exceptions.
It must include exactly one statement, or group of statements in curly braces.
exception
variable of Exception type can be used as the caught object. You must not delete the exception
Object! #define end_try |
Closing mark for the try catch construct.
This must be used to terminate the try catch finally constructs.
#define finally |
Finally block.
This block is executed in every case: either exception was thrown or not, caught or not. It must include exactly one statement, or group of statements in curly braces.
#define ooc_manage | ( | p_target, | |
p_destroyer | |||
) |
Manage a pointer.
Provides protection to a pointer, preventing memory leak in case of an exception. Pushes a pointer onto the top of the managed pointers' stack.
p_target | Pointer to the resource to be managed. |
p_destroyer | Appropriate destroyer function for the target (typically ooc_delete or ooc_free ). |
#define ooc_manage_object | ( | p_target | ) |
Manage an Object.
Provides protection to an Object, preventing memory leak in case of an exception. This is a comfortable shortcut for
p_target | Pointer to the Objcet to be managed. |
#define ooc_pass | ( | target | ) |
Removes the most recently pushed pointer from the managed pointers' stack.
Always use in the reverse order of using ooc_manage()!
The name is coming from passing the ownership of the pointer to an other object or function.
target | The pointer to be removed. |
target
itself. #define try |
Opens a try ...
catch block. It must include exactly one statement, or group of statements in curly braces.
enum error_codes |
Error codes.
These error codes are included in the Exceptions thorwn by the ooc core.
int exception_get_error_code | ( | const Exception | exception | ) |
int exception_get_user_code | ( | const Exception | exception | ) |
Exception exception_new | ( | enum error_codes | error | ) |
Creates a new ooc system Exception.
Creates a new ooc Exception, that must have an error_code of a valid ooc system error code.
error | ooc system error code. |
void ooc_rethrow | ( | void | ) |
Retrhows a caught exception.
Can be used only within a catch()
or a catch_any
block. Must be the last statement in the block!
void ooc_throw | ( | Exception | exception | ) |
Throws an exception.
Exceptions can be thrown anywhere but in Object destructors and in finally
blocks.
exception | The Object to be thrown. Must be a newly created object of Exception class or a derived class. ooc will manage this Exception object, you must not delete it yourself! |