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:51
Subject:
Re: Of fail, exceptions and catching
Message ID:
7ca3f0160505110650c76f047@mail.gmail.com
On 5/11/05, Luke Palmer <lrpalmer@gmail.com> wrote:
>     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()

Oh, just to avoid further confusion: In the baz() called under fatal,
it will only turn undefs that were generated by "fail" calls into
exceptions.  Other sorts of undefs will be returned as ordinary
undefs.

Likewise, in the bar() called under no fatal, it will only turn
exceptions that were generated by "fail" calls into undefs.  Other
sorts of exceptions stay as exceptions and propagate outward.

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