SPUG: Re: IO::All

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Mon May 24 23:35:17 CDT 2004

> Humor and playfulness, aside -- I'd call it "error handling lite", or
> "go ahead and let it die, if anyone cares, they'll wrap it with an
> eval and catch it".

>     eval {
>       # Ingy code with no error handling goes here...
>       }
>     warn "Ingy-instigated errors $@" if $@;

Thanks, I knew Ingy wouldn't leave anyone hangin' in the breeze.
I suspected 'eval' was the answer but I saw that tidbit about 
subclassing and throw() and was trolling for some examples ... :) 

> I had a brief discussion with Jack about it on a ride home, basically
> because Jack had asked a question about it during the talk. Much of
> the discussion centered around a historical error-handling conundrum
> -- propogate errors up the call stack and let callers check return
>    values (pessimistic -- check every call)
> -- throw an exception and have callers ignore or propogate it up the
>    call stack to anyone who cares (optomistic -- assume sucess, catch
>    errors at the "right" level, and ignore them when you can)

Difficult problem. I/O errors, though, tend to be dealt with very 
unevenly. We religously check 'open' succes but then assume 'print', 
etc. succeed. I try to emulate T. Christiansen's paranoia:

     From the Perl Cookbook:  
     When opening a file or making virtually any other system call,
     checking the return value is indispensable. Not every open succeeds;
     not every file is readable; not every piece of data you print can
     reach its destination. Most programmers check open, seek, tell, and
     close in robust programs. You might also want to check other functions.
     When you no longer have use for a filehandle, close it.... implicity 
     closes are for convenience, not stability, because they don't tell
     you whether the system call succeeded or failed. 

 I recall once a 'close(FH) or die $!' revealed a full file system.  
 This was a critical monitoring app so I was really thankful for 
 having heeded Tom's quiet crusade.

Charles DeRykus

More information about the spug-list mailing list