in reply to Idomatic Handling of Subroutine Error
That's the way Perl does it.eval { some_sub() }; if ($@) { # Handle exception here } sub some_sub { die "Bad stuff happened" if $some_exception_happens; }
Now, for a stylistic note - you shouldn't be doing the eval/$@ syntax for every single function call you make. Keep it for the critical parts of your system. In part, this is because of the overhead of eval. *shrugs*
Update: I stand corrected on the overhead. Thanks, btrott!
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Idomatic Handling of Subroutine Error
by btrott (Parson) on Sep 18, 2001 at 22:50 UTC | |
Re: Re: Idomatic Handling of Subroutine Error
by dvergin (Monsignor) on Sep 18, 2001 at 22:58 UTC | |
by dragonchild (Archbishop) on Sep 18, 2001 at 23:35 UTC | |
by dvergin (Monsignor) on Sep 18, 2001 at 23:53 UTC | |
by dragonchild (Archbishop) on Sep 19, 2001 at 00:24 UTC | |
by dvergin (Monsignor) on Sep 19, 2001 at 01:24 UTC |