John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

Everyone knows that die/eval is Perl's exception handling mechanism. However, this primitive can be used in many different ways.

Looking at CPAN, I see a few modules that provide higher-level constructs, including Exception-1.4 by Pete Jordan (mentioned on another thread here, which got me looking), and Exception-Class-0.8 by Dave Rolsky. The former is not in ActiveState's Repository, but the latter is. Why?? Does that mean one is more mature, more often used, etc.?

In general, which of the many exception systems is worth learning and using? Or do they all have their issues? If anyone's used exception handling in general or one of these modules, can you post your thoughts, for comparisons?


Replies are listed 'Best First'.
(tye)Re2: Throwing Exceptions and Error Handling
by tye (Sage) on Jun 15, 2001 at 00:44 UTC

    It'd be really nice if one of the dozen exception modules got included in the core (besides the very old, that is). I say this because one of the nice things about exceptions in other languages is that they interoperate.

    I have no idea whether any of the many exception modules can deal with each others' exceptions, and that has been a big reason why I haven't invested the time in any of them.

    Update based on John M. Dlugosz's reply: Yeah, that is all I am talking about. I suspect that one or more of those modules is well written enough that it can deal with exceptions from other modules intelligently. Perl gives us eval and die, but we need a common idiom for catch() that works with all reasonable exception modules. I'd base such a catch() around UNIVERSAL::isa() but with support for substring/regex matches on error text (since not all uses of die are going to be throwing objects).

    I think there is plenty of room for more than one way of writing catch(), etc. But we need an example in the core that sets a de facto standard for interoperability among them.

            - tye (but my friends call me "Tye")
      I suppose something to promote standardization should be included with the core, but still allow creative freedom and extension.
Re: Throwing Exceptions and Error Handling
by mikeB (Friar) on Jun 15, 2001 at 00:08 UTC

    I talked to Active State this morning about their Perl Repository, as their copy of DBI is out of date.

    Their response was "...modules are added based on input from our Perl Direct customers specifically and our customer base at large, but we don't add modules on request, per se, unless it's part of a service contract."

    FWIW, they said their copy of DBI should be updated soon.

    Too bad isn't as friendly as PPM :) As was pointed out earlier, installing CPAN modules manually isn't terribly difficult. However, "... laziness ..."
      CPAN would not be a pain to install at all if MakeMaker worked in ActiveState! I think it doesn't like spaces in file names... guess what the normal location for executables is?

      Strange answer though... I thought it was basically all of CPAN. Why leave something out?


        MakeMaker works fine on WinNT and beyond if you have a version of "make" and, if needed for the module, a C compiler. It doesn't work in Win9x because "cmd" is pretty darn stupid. Searching should find you many more details on the problems and some ways to work around some of them.

                - tye (but my friends call me "Tye")
        When I was writing Morse::Code I ran into a little trouble on win98 with MakeMaker, and one issue turned out to be a 'bug' in, here's a 'fix' i found for it in some perl forum (or newsgroup, i don't recall):
        UNINSTALL = $(PERL) -MExtUtils::Install \ -e "uninstall($$ARGV[0],1,1); print qq(\nUninstall is deprecated. Plea +se check the);" \ -e "print qq( packlist above carefully.\n There may be errors. Remove + the);" \ -e "print qq( appropriate files manually.\n Sorry for the inconvenien +ces.\n)" }; # fixed by crazyinsomniac changed all \" \" to qq()

        One reason I dislike cpan is because it is retardedly biased towards windows users, and updating cpan automatically is dang near impossible, not to mention the things it does by default (like keep some . files in root, etc)

        Disclaimer: Don't blame. It came from inside the void

        perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Re: Throwing Exceptions and Error Handling
by tadman (Prior) on Jun 15, 2001 at 00:21 UTC
    I had my curiosity piqued by the try/catch example in the Camel book, and brother_ab pointed out that there was the Error and Error::Unhandled modules that might be of interest.

    I've been doing more C++ lately and the exception methodology is a pretty straightforward way of handling errors.