use on; on failure { die "Some test failed\n" } try { if ($a) { ... } if ($b) { ... } if ($c) { ... } };
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 expecton
to be related toeval
. What I meant is that:should be equivalent toon failure {die "Test failed"}
try {
if ($a) {... }
if ($b) {... }
}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.if ($a) {... } else { die "Test failed" }
if ($b) {... } else { die "Test failed" } 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.