Idea derived from don't-hackery

Simon on 2002-05-03T09:36:02

use on; on failure { die "Some test failed\n" } try { if ($a) { ... } if ($b) { ... } if ($c) { ... } };


Exception::Handler

miyagawa on 2002-05-03T12:59:45

idea seems something similar to my Exception::Handler (not on CPAN yet). But I like this syntax more ;)

Scoping

ziggy on 2002-05-03T13:28:50

Do you think that on failure {...} should be lexically scoped? And stackable?
use on;

on failure {die "This block died"}
try {
    some_test();
}

on io_failure {die "I/O failure"}
try {
   some_io_test();  ## can throw failure / io_failure
}

on failure;
try {
   some_other_test();  ## generic failures s/b fatal, and I/O caught
}

Missing the point, I think

Simon on 2002-05-03T14:13:11

I don't expect on to be related to eval. What I meant is that:
on failure {die "Test failed"}
try {
    if ($a) { ... }
    if ($b) { ... }
}
should be equivalent to
if ($a) { ... } else { die "Test failed" }
if ($b) { ... } else { die "Test failed" }
But other than that, yes, it should be lexically scoped and stackable. This is quite easy to implement - I'll give the details in my next perl.com article.

Re:Missing the point, I think

ziggy on 2002-05-03T14:22:46

That's clearer. The use of on and try threw me. I expected on to be similar to on_* is for event handlers, and try to be an wrapper around an exception block.

EWRONGCONTEXT I guess.

Overall, it does look cool, even if the keywords tripped me up a bit.