Ed Avis wwwwrote:
> If LWP::Simple::get() fails it returns undef.  So if you want to check
> for errors you do something like
>     my $got = get($url);
>     if (not defined $got) {
>         # Handle error somehow, perhaps by dying
>     }
>     do_something_with($got);
> But a lot of the time, especially in 'simple' scripts that might use
> this module, you'll want to die() when a page could not be fetched.
> Even in larger programs where some recovery is possible you might
> prefer explicit error handling using die() to throw exceptions and
> eval {} to catch them.
> So it would be useful for LWP::Simple to have a global flag saying
> 'die on error, rather than returning undef'.  This would apply to
> head(), getprint() and the other methods as well as get().  The
> failure message passed to die() could include the URL and any status
> information like the HTTP response code.
> Do you think this is a good idea?  Should I send a patch?

No, I don't think you should.

All of the comparable Perl operations that I know about, including
all the Net:: modules, return a false value if they've failed.
In all these cases you're writing something like

  open my $fh, 'file' or die $!;

If you want to simply die on any attempt to open a file, pipe, net
connection or anything else then you can write:

  sub myopen {
    my $file = shift;
    open my $fh, $file or die $!;

and it doesn't need to be an option for each and every module and
built-in that does something similar.


Reply via email to