in reply to Thinking about module error handling

Stages of error handling:

  1. Hey, this is easy - just grab the return code, and use it...
    $rc = func(); if ($rc != 0) { die "Failed to func!"; }
  2. Oh, neat! Exceptions!
    eval { func(); } if ($@) { die "Failed to func: $@"; }
  3. Exceptions/OO are da bomb! Look at this!
    use Error::Handler; $rc = func(); if (not $rc->ok()) { die $rc->error_msg(); }
  4. Damn, that's way too much work...
    $rc = func(); if ($rc != 0) { die "Failed to func!"; }

At least, that's my experience...

Replies are listed 'Best First'.
Re^2: Thinking about module error handling
by sgifford (Prior) on Jun 14, 2005 at 00:04 UTC
    That's similar to my experience, which is why this module is API compatible with (1) and (4). On top of that simple and ubiquitous interface, it adds a way to find out more details about the error if the application programmer wants it---like $! but more general.