sql >> Base de Datos >  >> RDS >> Oracle

Excepción definida por el usuario con mensaje personalizado

El uso del procedimiento RAISE_APPLICATION_ERROR para generar la excepción le permite asociar un mensaje con el 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;

Documentación aquí - en particular, lea la sección titulada "Definición de sus propios mensajes de error:Procedimiento RAISE_APPLICATION_ERROR".

Comparte y disfruta.