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

Re: Of fail, exceptions and catching

Thread Previous | Thread Next
From:
Luke Palmer
Date:
May 11, 2005 06:46
Subject:
Re: Of fail, exceptions and catching
Message ID:
7ca3f016050511064656054030@mail.gmail.com
On 5/11/05, Aaron Sherman <ajs@ajs.com> 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; }
>         }
>         Foo.bar;
> 
> 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() {
        fail;
    }
    
    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)

Luke

Thread Previous | 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