I'm working on a Catalyst application and find myself doing something like:
eval { $form->model->create }; if ($@ =~ /column (\w+) is not unique/) { $form->get_field($1) ->get_constraint({type => 'Callback'}) ->force_errors(1); $form->process; }
Basically, I'm parsing the raw error message from my DBI engine (DBD::SQLite in this case).
If I switched to a different engine, I would probably get a different error message, so this would fail. Is there a way to find out the type of error and the column name it failed on? I checked $@, because it's an exception, but it only has a 'msg' method.
Ideally, I would like to do something like:
eval { $form->model->create }; if ($e =~ Exception::Class->caught('DBI::Unique')) { $form->get_field($e->column) ->get_constraint({type => 'Callback'}) ->force_errors(1); $form->process; }
Is there some way to achieve this?
--
Lyon
In reply to post mortem on DBI errors by redlemon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |