# More Custom Error Handling

- ## It is also possible for HandleError to hide an error, to a limited degree

  - use set_err() to reset $DBI::err and $DBI::errstr
  - alter the return value of the failed method
  $h->{HandleError} = sub {
  my ($errmsg, $h) = @_;
  return 0 unless $errmsg =~ /^\S+ fetchrow_arrayref failed:/;
  return 0 unless $h->err == 1234; # the error to 'hide'
  $h->set_err(0,""); # turn off the error
  $_[2] = [ ... ]; # supply alternative return value by altering parameter
  return 1;
  };

- ## Only works for methods which return a single value and is hard to make reliable (avoiding infinite loops, for example) and so isn't recommended for general use!

  - If you find a good use for it then please let me know.

## _

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