On Tue, 15 Aug 2000, David L. Nicol wrote:
> What if "try" were implied by the appearance of "catch" keywords, which
> expire at the close of their block?
>
> catch [EXCEPTION [, ...] ] BLOCK
> ,...
> BLOCK
[e.g.]
> catch Exception::MyDB, Exception::DBI {
> close_database();
> # other stuff
> }
> catch Exception::IO {
> close_network_connection();
> # other stuff
> }
I'd prefer to see the error handling come at the end, so that it
can be pushed off to one side. For example, if your formal syntax is:
BLOCK catch [EXCEPTION [, ...] ] [BLOCK] [, [EXCEPTION [, ...] ] [BLOCK]]
Then you can write the following:
{
close_database();
close_network_connection()
} catch Exception::DBI {handle_this;},
Exception::IO, Exception::IO::FOO{handle_that;}
This keeps the real code in one tight group and puts all the error
handling off to one side where it doesn't clutter up your visual field.
You can always rewrite it in a more traditional indentation, as:
{
close_database();
close_network_connection()
} catch Exception::DBI {handle_this;},
Exception::IO, Exception::IO::FOO{handle_that;}
But I like the first way better.
Note that I have marked the handler block as optional. If there
is no handler block found, the exception should just be eaten and the
program should continue. If this means that your program crashes...well,
that's the programmer's fault for not handling errors appropriately, not
the language's.
Dave