Oracle Exception Raise Application Error
Contents |
to your PL/SQL program. With many programming languages, unless you disable error checking, a run-time error oracle raise such as stack overflow or division by zero stops normal raise_application_error(-20001 processing and returns control to the operating system. With PL/SQL, a mechanism called exception handling
Difference Between Raise And Raise_application_error In Oracle
lets you bulletproof your program so that it can continue operating in the presence of errors. This chapter contains these topics: Overview of PL/SQL Runtime
Pragma Exception_init And Raise Application Error
Error Handling Advantages of PL/SQL Exceptions Summary of Predefined PL/SQL Exceptions Defining Your Own PL/SQL Exceptions How PL/SQL Exceptions Are Raised How PL/SQL Exceptions Propagate Reraising a PL/SQL Exception Handling Raised PL/SQL Exceptions Overview of PL/SQL Compile-Time Warnings Overview of PL/SQL Runtime Error Handling In PL/SQL, an error condition is called raise_application_error parameters an exception. Exceptions can be internally defined (by the runtime system) or user defined. Examples of internally defined exceptions include division by zero and out of memory. Some common internal exceptions have predefined names, such as ZERO_DIVIDE and STORAGE_ERROR. The other internal exceptions can be given names. You can define exceptions of your own in the declarative part of any PL/SQL block, subprogram, or package. For example, you might define an exception named insufficient_funds to flag overdrawn bank accounts. Unlike internal exceptions, user-defined exceptions must be given names. When an error occurs, an exception is raised. That is, normal execution stops and control transfers to the exception-handling part of your PL/SQL block or subprogram. Internal exceptions are raised implicitly (automatically) by the run-time system. User-defined exceptions must be raised explicitly by RAISE statements, which can also raise predefined exceptions. To handle raised exceptions, you write separate routines called exception handlers
Churchill Run-time errors arise from design faults, coding mistakes, hardware failures, and many other sources. Although you cannot anticipate all possible errors, you can plan to handle certain kinds of errors meaningful to
Raise_application_error Number Range
your PL/SQL program. With many programming languages, unless you disable error checking, a raise application error in sql server run-time error such as stack overflow or division by zero stops normal processing and returns control to the operating system. With raise_application_error is a procedure of which package PL/SQL, a mechanism called exception handling lets you "bulletproof" your program so that it can continue operating in the presence of errors. This chapter discusses the following topics: Overview of PL/SQL Error Handling Advantages of https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/errors.htm PL/SQL Exceptions Predefined PL/SQL Exceptions Defining Your Own PL/SQL Exceptions How PL/SQL Exceptions Are Raised How PL/SQL Exceptions Propagate Reraising a PL/SQL Exception Handling Raised PL/SQL Exceptions Tips for Handling PL/SQL Errors Overview of PL/SQL Error Handling In PL/SQL, a warning or error condition is called an exception. Exceptions can be internally defined (by the run-time system) or user defined. Examples of internally defined exceptions include division by zero and https://docs.oracle.com/cd/A97630_01/appdev.920/a96624/07_errs.htm out of memory. Some common internal exceptions have predefined names, such as ZERO_DIVIDE and STORAGE_ERROR. The other internal exceptions can be given names. You can define exceptions of your own in the declarative part of any PL/SQL block, subprogram, or package. For example, you might define an exception named insufficient_funds to flag overdrawn bank accounts. Unlike internal exceptions, user-defined exceptions must be given names. When an error occurs, an exception is raised. That is, normal execution stops and control transfers to the exception-handling part of your PL/SQL block or subprogram. Internal exceptions are raised implicitly (automatically) by the run-time system. User-defined exceptions must be raised explicitly by RAISE statements, which can also raise predefined exceptions. To handle raised exceptions, you write separate routines called exception handlers. After an exception handler runs, the current block stops executing and the enclosing block resumes with the next statement. If there is no enclosing block, control returns to the host environment. In the example below, you calculate and store a price-to-earnings ratio for a company with ticker symbol XYZ. If the company has zero earnings, the predefined exception ZERO_DIVIDE is raised. This stops normal execution of the block and transfers control to the exception handlers. The optional OTHERS handler catches
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the http://stackoverflow.com/questions/1760596/oracle-what-is-the-situation-to-use-raise-application-error company Business Learn more about hiring developers or posting ads with us Stack Overflow http://www.ibm.com/support/knowledgecenter/SS6NHC/com.ibm.swg.im.dashdb.apdv.plsql.doc/doc/c0053877.html Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Oracle: what is the situation to use RAISE_APPLICATION_ERROR? up vote 13 down vote favorite 5 We can use RAISE raise application to fire an exception. What particular situations do we need to use RAISE_APPLICATION_ERROR? Thanks. oracle share|improve this question asked Nov 19 '09 at 2:56 Ricky 8,3932762100 I found a useful link for similar question. toadworld.com/platforms/oracle/b/weblog/archive/2010/07/14/… –gmail user Feb 6 '14 at 16:30 add a comment| 4 Answers 4 active oldest votes up vote 23 down vote accepted There are two uses for RAISE_APPLICATION_ERROR. The first is to replace generic Oracle exception raise application error messages with our own, more meaningful messages. The second is to create exception conditions of our own, when Oracle would not throw them. The following procedure illustrates both usages. It enforces a business rule that new employees cannot be hired in the future. It also overrides two Oracle exceptions. One is DUP_VAL_ON_INDEX, which is thrown by a unique key on EMP(ENAME). The other is a a user-defined exception thrown when the foreign key between EMP(MGR) and EMP(EMPNO) is violated (because a manager must be an existing employee). create or replace procedure new_emp ( p_name in emp.ename%type , p_sal in emp.sal%type , p_job in emp.job%type , p_dept in emp.deptno%type , p_mgr in emp.mgr%type , p_hired in emp.hiredate%type := sysdate ) is invalid_manager exception; PRAGMA EXCEPTION_INIT(invalid_manager, -2291); dummy varchar2(1); begin -- check hiredate is valid if trunc(p_hired) > trunc(sysdate) then raise_application_error (-20000 , 'NEW_EMP::hiredate cannot be in the future'); end if; insert into emp ( ename , sal , job , deptno , mgr , hiredate ) values ( p_name , p_sal , p_job , p_dept , p_mgr , trunc(p_hired) ); exception when dup_val_on_index then raise_application_error (-20001 , 'NEW_EMP::employee called '||p_name||' already exists' , true); when invalid_manager then raise_application_error (-20002 , 'NEW_EMP::'||p_mgr ||' is not a valid manager'); end; / How it looks: SQL> exec new_emp ('DUGGAN', 2500, 'S