redlemon has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: post mortem on DBI errors
by mje (Curate) on Jan 23, 2009 at 10:31 UTC | |
Re: post mortem on DBI errors
by andye (Curate) on Jan 23, 2009 at 14:27 UTC | |
by redlemon (Hermit) on Jan 23, 2009 at 15:04 UTC |
Back to
Seekers of Perl Wisdom