2010-07-27

exceptions of Golang and Vala

7.17: news.adda/google'golang/design/exceptions:
. coupling exceptions to a
control structure,
as in the try-catch-finally idiom,
results in convoluted code.
. a routine that signals an exception
will then run a recovery routine
as it is closing for the return
-- sufficient to handle catastrophe
but requires no extra control structures
and, when used well,
can result in clean error-handling code.
7.25: news.adda/exceptions/Vala:

. vala has checked exceptions, not class-based, no wrapping
[. I changed the lexicon to match Ada's,
and much of the syntax to match adda's:]

. error domain with multiple error codes:
MyError.exception: { FOO, BAR }

. must be declared in method signature,
part of the contract:
method().proc raises MyError:
( raise FOO (message: "not enough foo") );

. must be handled or propagated:
[this is a declare block
(having an ex.label (exception)
defines a try-catch block)]

.(
method ();
ex:
e.MyError:
stderr(e`message);
)
. Although the compiler emits
warnings for ignored errors
it does not abort the compilation process.
This allows prototyping without proper error handling
and will hopefully prevent
forgotten empty catch blocks.