This feels like such a hack, but it works. I simply want to weed out constraint errors from other errors within Class::DBI.

try {
    $cart = $self->create($data);
} catch Error with {
    my $E = shift;
    if ($E->text =~ /^validate_column_values error:\s+(.*)?\s+Commerce/i) {
        throw Commerce::Exception::Constraint(-field => $1, -text => $E->text);
    } else {
        throw Commerce::Exception(%{$E});
    };
};

I’m sure there is some $SIG{__DIE__} or Carp::croak symbol table magic I could work. But that’s assuming I know what the hell I’m doing in the first place.



Assuming I can get to it at the right time, there is the HandleError attribute of DBI clases. That might do it.


For the love of all that is holy, how in the hell did I miss this section on Exceptions? #$@#$%! Of course, the question still remains, is it appropriate to makje Exceptions decisions based on the message test, or do the hooks need to be deeper?

See more posts about: perl | All Categories