Error Handling

Error Handling is another pattern language of the ArcusProject, written by KlausRenzel?. It contains a set of patterns to handle abnormal conditions in business information systems, using either exceptions or return code techniques.

You can download the complete language from

Please send us any comments you have.

-- JensColdewey


Error handling has always been something that complicates programming. Me and a friend[2] would always have interesting discussions about it in terms of generic programming.

It is even tougher when you are trying to write a generic programming library and have some meaningful form of efficient error handling. Exceptions help with the efficiency problem (you don't have to check returns codes on every call) but they can present some problems with resource cleanup (GarbageCollection can help, but it is not without its problems too).

Also, because exceptions represent another form of flow control, it is unclear if they should be used just for error conditions or conditions that are just out of the normal flow of control.

Another interesting problem is how to actually identify errors. This is especially tricky in embedded systems, where if something goes wrong it can be very difficult to figure out what.

One approach I have taken is to make errors objects that answer the 6 basic questions of an error (who, what, when, where, why, and how). And for identifying the "what" in a large systems I use SNMP like OID's that can help pinpoint the error to a particular component of the system.

Comments?

-- MarkGrosberg


When I need complex error reporting capability in C, I find its mechanism of passing around exception structure references really helps out. E.g.:

 void main(int argc, char *argv[]) {
   MyException? e;
   Handle someResource;

resetException_(&e);

someResource = getNewResource(&e); frobnicateResource_with_(someResource, someComputedValue(), &e); disposeResource_(someResource, &e); }

The onus is on the called function to cull themselves if an exceptional condition has been detected.

 void frobnicateResource_with_(Handle aResource, int someValue, MyException? *e) {
   if(e && (e.error == OK)) {
     // ...
   }
 }

It's usually not that big a burden, and it works really well; especially since most functions have to check their input arguments anyway.

For those who are aware of it, yes, I learned this trick from CORBA. :-)

As I was typing this, I realized that you could even extend the exception structure with a data and function pointer to kinda sorta implement Lisp-inspired restarts. This requires a more event-driven programming approach to implementing your API, but it should be doable. I might do some extra research into this someday. --SamuelFalvo?


See also ChecksPatternLanguage, DoOrDie


EditText of this page (last edited November 10, 2014) or FindPage with title or text search