Syntactic Confectionery Delight | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
See $! in perlvar. You can't reliably set $!. If you have warnings on, you'll get Argument "Error loading data!" isn't numeric in scalar assignment because $! isn't a normal variable, and expects a numerical system error code. (Re: warnings, see Use strict warnings and diagnostics or die).
The usual way of indicating a failure in Perl is to die, which functions as an exception that can be caught downstream, e.g. which could be invoked as my $obj = eval{coolobject->new} or die "$@"; If you absolutely want to pass an error and return an undef, you could set $@ manually, but this is probably poor form. If you are rolling your own objects for fun/education, I'd recommend you look at perltoot. If you are rolling objects for deployment, I'd look at (and use) some prior art like Moose, Mouse... <Node text goes above. Div tags should contain sig only> #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way. In reply to Re: How do I report an error back to the user of my object?
by kennethk
|
|