Article View: comp.sys.acorn.tech
Article #280Exception handling in C.
From: Ug!
Date: Mon, 09 Nov 1992 00:50
Date: Mon, 09 Nov 1992 00:50
43 lines
2533 bytes
2533 bytes
I'd like to discuss a few things about what I am implementing at the moment, first among them being the issue of exception handling in C. Exception handling is always a messy business, and C doesn't cope particularly well with it, although in fact I've yet to meet a language which does. For those of you who don't know what exception handling is, it's what the language does when things go wrong. For instance, what happens when you do a divide by zero? Much of the exception handling is an academic question: with facilities built into the language, you are stuck with what you are given. However, in your own code, you have some say over how you want to handle exceptional cases. Three things I wanted to have with an exception handling facility were: * every module which raised an exception should include some facility for coping with this exception (usually by displaying an error message to the user). This means that you should not get unhandled exceptions ever. However, there should still be some fallback facility for handling buggy code. * exceptions should be interceptable. For instance, if I call a routine to open a file, and the routine raises an exception if that file doesn't exist, then an error message may not always be appropriate for that situation. I should be able to intercept that exception, and in this case, decide not to raise an error. * exceptions should not alter the normal flow of code. If you allow an exception to land you somewhere else in the program, then you end up with a mess that makes spaghetti look friendly. Instead, exceptions should be coped with in a manner resembling interrupt handlers. Those were my base ideas for handling exceptions. What I came up with was essentially each module registering a handler with an 'error' module. The most recent registered handler is passed the exception first. If it doesn't handle the exception, then the next most recent handler is called, and so on. How do other people cope with exceptions? Is there something I'm missing? I've noticed that my way of doing adds the additional ability to cope well with internationalisation, which is an added bonus. Ug!
Technical Details
Message-ID:
<1992Nov9.135023.12048@waikato.ac.nz>Path:
arc1-ca.pugleaf.net!sparky!uunet!decwrl!waikato.ac.nz!bwcShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!waikato.ac.nz!bwc From: bwc@waikato.ac.nz (Ug!) Newsgroups: comp.sys.acorn.tech Subject: Exception handling in C. Message-ID: <1992Nov9.135023.12048@waikato.ac.nz> Date: 9 Nov 92 13:50:23 +1300 Organization: Vooniersity fo Kaiwato Lines: 43