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

Re: Of fail, exceptions and catching

Thread Previous | Thread Next
Luke Palmer
May 11, 2005 06:46
Re: Of fail, exceptions and catching
Message ID:
On 5/11/05, Aaron Sherman <> wrote:
> Given:
>         "fail" with configurable behavior
>         "no fatal" to make "fail" just warn

Juerd is right here, it doesn't warn.  Instead of "die"ing, it returns
an undef with some helpful diagnostic information (an "unthrown
exception" as Larry has been calling it).

>         "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; }
>         }
> That is, bar() picks up a lexically scoped "use fatal"

No it doesn't.  The fatal that refers to bar's return value belongs to
the caller of bar.  Here's another example:

    sub foo() {
    use fatal;
    sub bar() {
        foo();   # foo() throws exception

    no fatal;
    sub baz() {
        foo();   # foo() returns undef

    use fatal;
    bar();  # propagates exception from foo()
    baz();  # turns baz()'s (from foo()'s) undef into an exception
    no fatal;
    bar();  # turns exception thrown from foo()'s into an undef
    baz();  # returns the undef that it got from foo()

Does that clarify things?  (I could tell there was some
misunderstanding going on, but I had a hard time explaining it. 
Hopefully this example will clear things up)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About