# Custom Error Handling

- ## Don’t want to just Print or Raise an Error?

  - Now you can Handle it as well…
    $h->{HandleError} = sub { … };

- ## The HandleError code

  - is called just before PrintError/RaiseError are handled
  - it’s passed
    - the error message string that RaiseError/PrintError would use
    - the DBI handle being used
    - the first value being returned by the method that failed (typically undef)
  - if it returns false then RaiseError/PrintError are checked and acted upon as normal

- ##

- ## The handler code can

  - alter the error message text by changing $_[0]
  - use caller() or Carp::confess() or similar to get a stack trace
  - use Exception or a similar module to throw a formal exception object

Previous slide | Next slide | Back to first slide | View graphic version