Note that the exception handlers are only necessary for C code. This will usually by something like this:
TRY {
// some code...
if (errno)
THROW("Error %d: %s", errno, strerror(errno));
// more code...
} CATCH(char *msg) {
output_error("Exception caught: %s", msg);
} ENDCATCH
In C++ code, you can use THROW() to throw an exception that is to be caught by the main system exception handler.
The recommended format for exception messages is as follows:
throw_exception("object_tree_add(obj='%s:%d', name='%s'): memory allocation failed (%s)", obj->oclass->name, obj->id, name, strerror(errno));
static, you should include the file in which it is implemented, as in throw_exception("object.c/addto_tree(tree.name='%s', item.name='%s'): strcmp() returned unexpected value %d", tree->name, item->name, rel);
throw_exception("%s(%d): unexpected EOF", filename, linenum);
GL_THROW("%s:%d circuit %d has an invalid circuit type (%d)", obj->oclass->name, obj->id, c->id, (int)c->type);
Typedefs | |
| typedef struct s_exception_handler | EXCEPTIONHANDLER |
| the exception handler structure | |
Functions | |
| EXCEPTIONHANDLER * | create_exception_handler (void) |
| Creates an exception handler for use in a try block. | |
| void | delete_exception_handler (EXCEPTIONHANDLER *ptr) |
| Deletes an exception handler from the handler list. | |
| char * | exception_msg (void) |
| Retrieves the message of the most recently thrown exception. | |
| void | throw_exception (char *format,...) |
| Throw an exception. | |
| EXCEPTIONHANDLER * create_exception_handler | ( | void | ) |
Creates an exception handler for use in a try block.
Definition at line 64 of file exception.c.
References output_fatal().
| void delete_exception_handler | ( | EXCEPTIONHANDLER * | ptr | ) |
Deletes an exception handler from the handler list.
| ptr | a pointer to the exception handler |
Definition at line 80 of file exception.c.
References output_fatal().
| char * exception_msg | ( | void | ) |
Retrieves the message of the most recently thrown exception.
Definition at line 129 of file exception.c.
| void throw_exception | ( | char * | format, | |
| ... | ||||
| ) |
Throw an exception.
| format | the format string |
Definition at line 99 of file exception.c.
References output_fatal().
Referenced by aggregate_value(), class_get_first_property(), cmdarg_load(), convert_from_timestamp(), global_create(), load_tzspecs(), local_datetime(), object_close_namespace(), object_create_foreign(), object_create_single(), object_dump(), object_get_unit(), object_open_namespace(), random_exponential(), random_pareto(), random_sampled(), random_weibull(), schedule_index(), strdatetime(), timestamp_set_tz(), and unit_init().