oracle 如何在异常处理块中重新引发 pl/sql 异常?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14978431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to re-raise pl/sql exception in exception handling block?
提问by user2090855
I have the following procedure which is used by some applications:
我有一些应用程序使用以下程序:
procedure p1
is
begin
bla bla bla;
end;
But there is no exception handling block. So applications were written according this feature.
但是没有异常处理块。所以应用程序是根据这个特性编写的。
Now I need to log errors in p1. But it shouldn't affect applications that use this procedure.
现在我需要在 p1 中记录错误。但它不应影响使用此过程的应用程序。
Something like this:
像这样的东西:
procedure p1
is
begin
bla bla bla;
exception when others then
log_error(sqlcode, sqlerrm);
raise_new_exception (sqlcode, sqlerrm);
end;
In case of raise_application_errorfirst parameter should be in range [-20000, -20999]. So if there raises exception no_data_found, it cannot raise this error.
如果raise_application_error第一个参数应该在 [-20000, -20999] 范围内。因此,如果引发异常 no_data_found,则不会引发此错误。
In case of exception_init, second parameter should not be variable. It must be numeric literal.
在exception_init 的情况下,第二个参数不应是可变的。它必须是数字文字。
PS: As temporary solution, I'm using execute immediate
PS:作为临时解决方案,我正在使用立即执行
回答by igr
If your error stays the same, change to
如果您的错误保持不变,请更改为
...
exception when others then
log_error(sqlcode, sqlerrm);
raise;
end;
/
This is explained in the documentation.
这在文档中进行了解释。