检索异常消息我对在插入其中的某些情况下会引发异常运行的表的触发功能。从PostgreSQL函数
我保持催化剂上运行旧的Perl应用程序,创建了一个事务,并在表中插入行。
当触发函数抛出一个例外,我希望能够打印出刚错误消息我扔,而不是任何调试信息(数据库操作,背景,perl的文件等)。
因此,举例来说,如果我的函数抛出这样的:
raise exception 'Item with id % cannot be shipped at this time.', new.id;
我想只看到
Item with id 13 cannot be shipped at this time.
,而不是
DBIx::Class::Row::insert(): DBI Exception: DBD::Pg::st execute failed: ERROR: Item with id 13 cannot be shipped at this time. [for Statement "INSERT INTO ... at /home/../lib/Class/Controller/Inv.pm line 260
Perl代码是目前东西像
$c->model('Class')->schema->txn_do(sub {
...
eval {
$shipment->insert;
1;
} or do {
$error = [email protected];
last;
};
if ($error) {
$c->stash->{error} = $error;
}
);
谢谢。
呀。我的意思是我想过使用正则表达式。认为有可能已经更...我猜“适当的”做这件事的方式。 – rhyek