[Lazarus] exception handling

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sun Mar 13 09:19:35 CET 2011


Bernd schrieb:
> 2011/3/9 Hans-Peter Diettrich <DrDiettrich1 at aol.com>:
> 
>> An exception down in some calculation doesn't give you any clue of what
>> exactly went wrong, only that *something* went wrong.
> 
> It can often be useful and remove a lot of if/else for cleanly exiting
> a bunch of nested loops and functions (and also save clock cycles and
> make the code much more compact and clearer) if you let it
> *automatically* unwind the the call stack (instead of writing code for
> this) whenever the exception occurs (of course only if you really know
> why your exceptions would occur).

IMO exception handling (SEH) serves two strictly different purposes:
try-finally allows to protect resources and clean up, while
try-except allows to modify the control flow.

My comment was about proceeding after an exception occured, i.e. where 
to place the try-except block, and what to do within that exception 
handler. When a whole operation should be aborted on an invalid 
argument, raising an exception will be fine, and catching it in some 
higher level in the call stack (or in the default application handler). 
Otherwise, when the error can be detected and/or handled in the same 
place, throwing an exception can be evitable overhead.

DoDi





More information about the Lazarus mailing list