1. RE: Exception Handling

-------Phoenix-Boundary-07081998-

Hi Chris Bensler, you wrote on 3/24/02 4:34:58 PM:

>I'm hoping to get some feedback on this library. Positive and negative
>criticism is appreciated.
>
>I've written an error library and implemented what I 'think' is a
>exception handling system.
>
>Sorry for the lack of documentation, but it's still in prototype.
>
>Basically, I know nothing of exception handling other than my own
>theories and the other implementations that I have seen. I'd like to get
>some more insight as to the how and why.
>Is this system sufficient? What are the main properties of an exception
>handling system?
>
As I understand it:
You throw an exception with something like
   if file_open (nm, mode) = ERROR then
      throw (file_open_error)

While throw() looks like a call, it is actually a return which returns
to the nearest catch statement. This catch statement
may be in the throwing function, or in any of it's callers.
Throw is therfore a sort of multilevel return, that 'unwinds' the
call stack looking for a catcher.

Example:
procedure open_file (sequence name)
   if open(name, "r") == -1 then
      throw (file_open_err)
   end if
   ...  --perform other housekeeping
end procedure

procedure init_logfile (sequence path)
   open_file (path & "log")
   ...
end procedure

procedure main ()
again:
   init_logfile (path)
   do_process()
   report_results ()
:catch:
   if error = file_open_err and retrys = 0 then
      retrys = 1
      path = getenv_path(); --try a different path this time
      goto again
   end if
   rethrow () --let a higher catch (if any) handle it
end procedure

The important thing is that we have decoupled the place where
the error is handled from the place where it was generated.

I can't imagine how this can be done except by modifying the
interpreter code (which is quite easy).

Karl Bochert

-------Phoenix-Boundary-07081998---

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu