从Dot Net中的Oracle异常中获取实际错误消息

时间:2012-04-28 06:49:03

标签: oracle stored-procedures

我有这个程序:

create or replace PROCEDURE MyProc
(
     <some-parameters>
)
AS
  BEGIN
    if(<some-condition>) then
        RAISE_APPLICATION_ERROR('my custom error message');
    end if;
  END;

从C#调用时:

try
{
    <call procedure>
}
catch(OracleException x)
{
    lblMessage.Text = x.Message;
}

我收到如下错误消息:

ORA-28008: my custom error message ORA-06512: at blah, line blah ORA-06512: at line blah

我只想:

my custom error message

没有innerException。错误收集没有帮助。使用Exception而不是OracleException时的情况相同。

我错过了什么?

我可以使用字符串操作,但错误消息的格式有多固定?

2 个答案:

答案 0 :(得分:0)

我使用返回参数来捕获php。我重新使用相同的技术将在.net中有用。 (我假设可以在异常处理中捕获自定义消息并仅重新引发该自定义消息,但在方法下面确实有效。:)

create or replace PROCEDURE MyProc (p_result out varchar2)
is
  ...
begin
  ...
  if error then
    p_result := 'my custom error message';
    return; -- exit procedure 
  end if;

  p_result := 'ok';
end;

答案 1 :(得分:-1)

尝试

PKG_MSG.RAISE_ERROR(0,null,'我的自定义错误消息',null,null,null,null,null,null,null,null,null,null);

而不是

RAISE_APPLICATION_ERROR('我的自定义错误消息');