Exception Handling
26th January 2010
These are lecture notes from my Computer Science course, not a general reference for "Exception Handling"
Ada & exception handling
- The domain of the exception is the block (the
begin).
- Exception propagation.
- No syntactic relationship between subprograms and exceptions; so the exceptions that might be raised are specified at a package level, not a procedure level. This can be a bit annoying.
- Only strings can be passed to handlers.
- Exceptions could (accidentally) be propagated to blocks that don’t know what those sorts of exceptions are.
- Catch ‘other’ exceptions using
when others. But that’s all or nothing, no hierarchy (I think).
Java & exception handling
- Domain of exception is explicitly indicated (
try statement). This block is then considered guarded.
- Exception propagation.
- Use
catch (Exception E) to catch all exceptions. Can have hierarchy.
- Supports
finally clause as part of a try statement. This code is guaranteed to execute whether you caught an exception or not. Not easy to do in Ada; finalisation objects (will be in the practicals).
Erlang/OTP (ignore if revising)
try and catch too.
- Exception propagation.
- OTP supervisor deals with exceptions; restarts threads/terminates other threads if it is configured to. Very flexible in that regard.
- Hierarchy possible too, as it’s just pattern patching on the exception.
Exception propagation
- No handler associated with a block/procedure? Maybe consider it as programmer error & so report at compile time. May not be possible though as exception may be within a procedure so no idea if it needs to handle an exception or not (context sensitive).
- Instead, use propagation.
Resumption versus termination
- Resumption: Invoker continues after the exception has been handled. Difficult; might not be able to repair errors or backtrack. Arithmetic overflow in the middle of an expression would be difficult. However if you can do it; it’s asynchronous - it works a bit like a software interrupt.
- Termination: Guess.
What about no exception handling?
Some languages (C?) return negative integers instead of having exceptions. An exception handler is a bit like a GOTO; which is Very Bad(tm). But in RTS we need error recovery and need to be able to cope with errors and so exception handling gives you a structured way of dealing with that :)
Comments
blog comments powered by Disqus