User-defined execption with custom message

柔情痞子 提交于 2019-12-05 18:53:14

Using the RAISE_APPLICATION_ERROR procedure to raise the exception allows you to associate a message with the error:

DECLARE
  e EXCEPTION;

  PRAGMA EXCEPTION_INIT (e, -20100);
BEGIN
  RAISE_APPLICATION_ERROR(-20100, 'This is the user-supplied message');
EXCEPTION
  WHEN e THEN
    DBMS_OUTPUT.PUT_LINE('Caught e: ' || SQLCODE || ' ' || SQLERRM);
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Caught something else: ' || SQLCODE || ' ' || SQLERRM);
END;

Documentation here - in particular, read the section titled "Defining Your Own Error Messages: Procedure RAISE_APPLICATION_ERROR".

Share and enjoy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!