in reply to <rant>CPAN modules failing to check for write errors</rant>

One thing that nobody seems to have brought up in the above discussion is that you really shouldn't $xml->save($data) or die and quit the program during a save data routine. If you quit the program, you immediately loose all the data.

What really needs to be done is to return an error message so the rest of the program can alert the user, or save an emergency file or something.

____________________
Jeremy
I didn't believe in evil until I dated it.

Replies are listed 'Best First'.
Re: Re: <rant>CPAN modules failing to check for write errors</rant>
by Anonymous Monk on May 30, 2004 at 09:49 UTC
    Well ok in that particular case, you'd:
    eval { $xml->save($data) };
    
    do_whatever($@) if $@;
      And this is exactly why I don't like exceptions. Rather than handling errors within the module, the code just sproings them up to the next level.

      Except then everyone has to check all their code all the time for exceptions. If one person doesn't, then a trivial error rips it's way up the call stack until it is caught by a piece of code that may not even be aware of the sub-sub-sub-modules existance.

      Just like threading, some people immediately try to do everything through exceptions even when it isn't necessary. I rather see people writing decent code that tries to recover and do the right thing.

      If that's going to be the standard answer in Perl6, then I can see I'll be in for a lot of debate.

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.

        I rather see people writing decent code that tries to recover and do the right thing.
        True - but when you don't know who's going to use your module, and in what ways, it may be difficult to know what the right thing is, but that's a fair point.

        Personally I do mix exceptions and return values depending on the module and script (not quite as chaotic as it sounds :) - I've certainly found that a fairly judicial use of exceptions can clean code up no end, and the less code I write, the less chance for error.

        I've built a few larger applications/modules around Exception::Class, and I'd hate to try to re-implement them checking every return value, but as I said in an earlier post, I always found exceptions in Java a pain in the **** for the reasons you've stated.

        As for P6 - who knows? Every time I read (or try to read) an appocalypse I feel worried, but then Damian usually manages to make it all sound ok. The only thing I've seen so far that sounds terrible is whitespace determining how a method is called - P6 should definitely absorb some of Pythons better features, but I'd prefer it if they left whitespace the hell alone :)