On Mon, 30 Apr 2001, Matt Sergeant wrote:

> On Mon, 30 Apr 2001, Jeffrey W. Baker wrote:
>
> >
> >
> > On Mon, 30 Apr 2001, Matt Sergeant wrote:
> >
> > >
> > > > [1] for my Perl exception package (yes, another one :) which, in its
> > > > development version, now mostly does the Right Thing for mod_perl. See
> > > > http://sourceforge.net/projects/perlexception/ for the curious.
> > >
> > > Since I'm doing the mod_perl exception handling talk at TPC, I feel
> > > obligated to ask about this...
> > >
> > > It doesn't seem any different from Error.pm to me, except in syntax. Maybe
> > > you could expand on why/where it is different?
> >
> > I tried using some different exception packages in the past.  What I
> > realized is, die() and eval {} ARE Perl's exception handling mechanism.
> > die() and eval {}, together, have complete exception throwing and handling
> > functionality.  As a bonus, they lack Java's exception bondage and
> > discipline.
> >
> > So, what's wrong with die() and eval {}?
>
> Nothing, IMHO. In fact I've now switched away from using Error.pm's
> try/catch syntax, because it creates closures and it's really easy to
> generate memory leaks that way with mod_perl. But I still use Error.pm's
> exception object structure...
>
> Without some sort of structured exception handling, you don't know exactly
> what type of exception was thrown. For example, in AxKit I need to know in
> certain places if an IO exception occured, or if it was some other kind of
> exception. I could do this with regexps, but then I'm relying on people
> using the right strings in their error messages. Plus exception objects
> can give you a stack trace, which eval catching a string can't (well, it
> kinda can in a few ways, but not in quite as clean a manner).
>
> Try it though, you might be surprised you like it. (unless by die() and
> eval{} you mean you're already using exception objects, in which case I'm
> preaching to the choir ;-)

Yes precisely.  It used to be that you could only die() with a string, but
5.<mumble> gave us die() with a reference to an object and at that moment
the system was complete.  The creation of a rational exception object type
is left to the discretion of the system designer (thankfully).

-jwb

Reply via email to