[Mono-list] exceptions and ECMA issues

James Perry jeperry@uwaterloo.ca
Wed, 22 Aug 2001 00:38:54 +0000 (GMT)

On Tue, 21 Aug 2001, Paolo Molaro wrote:

> 2) rethrow opcode. It is not clear where the search for an handler
> should begin after a rethrow: should it start from the beginning,
> from the last handler found or from the parent method?
> Consider:
> Restarting from the beginning will result in an infinite loop,
> so, what other option should I choose?

The sensible solution, IMHO, is to go to the next enclosing try block, not
the next catch handler.

First, the specs:

Part III, 3.23, lines 7-9:
  ... It throws the same exception that was caught by this handler.

My interpretation is that this should be treated exactly like a
traditional throw - catch blocks aren't within protected try blocks so the
exception should go to the next highest-level try{} block.

Secondly, the principle of least astonishment:

If rethrow goes up to the previous method then it will always go to the
next method - you can get around this behaviour if you want by writing
type-smart catch handlers, but that's really got to be intended behaviour.

If rethrow goes to the next catch block for the same try{}, and one of
your catch handlers wants an interface, you really have no clue where it's
going to go unless you do a lot of work trying to figure that out.

rethrowing to the parent method is the least astonishing, so it should be
the behaviour implemented.

 - James