develooper Front page | perl.perl6.language | Postings from May 2005

Of fail, exceptions and catching

Thread Next
From:
Aaron Sherman
Date:
May 11, 2005 04:44
Subject:
Of fail, exceptions and catching
Message ID:
1115811868.4592.1335.camel@pps
Given:

	"fail" with configurable behavior
	"no fatal" to make "fail" just warn
	"use fatal" to make "fail" throw exceptions

A question came up on #perl6 for the following code:

	no fatal;
	class Foo {
		use fatal;
		method bar() { fail; }
	}
	Foo.bar;

That is, bar() picks up a lexically scoped "use fatal", but the caller
of bar desires non-fatal behavior.

Possible results and reasons for them:

      * Warning -- For this to work, I think you would need an implicit
        CATCH block wrapper around each statement in a "no fatal"
        section. This could be simulated by wrapping the entire no fatal
        section in a continuation closure which is then called inside a
        CATCH block which warns and re-invokes the continuation... if
        continuations can be re-invoked after exceptions. That's an
        interesting question on it's own actually.
      * Fatal exception -- This implies that the callee's lexically
        scoped fatal preference wins, which might be a reasonable thing
        in concept, but seems to present no control to the user of a
        module when the module author has specified a preference.
        Perhaps that's a good thing. Perhaps it's bad. I do see a
        problem with a program that uses several modules, all of which
        have different opinions about fatality...
      * Warning -- Another reason that you might get a warning would be
        that there is some sort of dynamically scoped imposition of a
        non-fatal context from "no fatal". That seems the least likely
        to me, but I thought that I'd bring it up.

This came up when someone was considering writing a module, and was
saying that he really wanted "use fatal" as the default for his modules.
That seems like a reasonable thing to want, but I'm not sure how it
could be controlled correctly.

-- 
Aaron Sherman <ajs@ajs.com>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About