Oracle User Defined Error Numbers Range
Contents |
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 your exception handling in oracle stored procedure example PL/SQL program. With many programming languages, unless you disable error checking, a run-time error oracle raise exception with message such as stack overflow or division by zero stops normal processing and returns control to the operating system. With PL/SQL, a oracle sqlerrm 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 PL/SQL Exceptions Predefined oracle predefined exceptions 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 out of memory. Some
Exception Handling In Oracle 11g Example
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 all exceptions that the block does not name s
to your PL/SQL program. With many programming languages, unless you disable error checking, a run-time error such as stack overflow or division
Types Of Exceptions In Oracle
by zero stops normal processing and returns control to the operating system. oracle error handling best practice With PL/SQL, a mechanism called exception handling lets you bulletproof your program so that it can continue oracle dup_val_on_index operating in the presence of errors. This chapter contains these topics: Overview of PL/SQL Runtime Error Handling Advantages of PL/SQL Exceptions Summary of Predefined PL/SQL Exceptions Defining Your https://docs.oracle.com/cd/A97630_01/appdev.920/a96624/07_errs.htm 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 an exception. Exceptions can be internally defined (by the runtime system) or user defined. Examples of internally defined exceptions include https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/errors.htm 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. 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. For information on managing errors when using BULK COLLECT
here for a quick overview of the site Help Center Detailed answers to any questions you http://stackoverflow.com/questions/6020450/oracle-pl-sql-raise-user-defined-exception-with-custom-sqlerrm might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or https://dfitzjarrell.wordpress.com/2008/05/02/ive-never-seen-that-error-before/ posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community in oracle of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Oracle PL/SQL - Raise User-Defined Exception With Custom SQLERRM up vote 45 down vote favorite 21 Is it possible to create user-defined exceptions and be able to change the SQLERRM? For example: DECLARE ex_custom EXCEPTION; exception handling in BEGIN RAISE ex_custom; EXCEPTION WHEN ex_custom THEN DBMS_OUTPUT.PUT_LINE(SQLERRM); END; / The output is "User-Defined Exception". Is it possible to change that message? EDIT: Here is some more detail. I hope this one illustrates what I'm trying to do better. DECLARE l_table_status VARCHAR2(8); l_index_status VARCHAR2(8); l_table_name VARCHAR2(30) := 'TEST'; l_index_name VARCHAR2(30) := 'IDX_TEST'; ex_no_metadata EXCEPTION; BEGIN BEGIN SELECT STATUS INTO l_table_status FROM USER_TABLES WHERE TABLE_NAME = l_table_name; EXCEPTION WHEN NO_DATA_FOUND THEN -- raise exception here with message saying -- "Table metadata does not exist." RAISE ex_no_metadata; END; BEGIN SELECT STATUS INTO l_index_status FROM USER_INDEXES WHERE INDEX_NAME = l_index_name; EXCEPTION WHEN NO_DATA_FOUND THEN -- raise exception here with message saying -- "Index metadata does not exist." RAISE ex_no_metadata; END; EXCEPTION WHEN ex_no_metadata THEN DBMS_OUTPUT.PUT_LINE('Exception will be handled by handle_no_metadata_exception(SQLERRM) procedure here.'); DBMS_OUTPUT.PUT_LINE(SQLERRM); END; / In reality, there are dozens of those sub-blocks. I'm wondering if there's a way to have a single user-defined exception for each of those sub-blocks to raise, but
as evidenced by the history of searches on the Internet for this error number. Unfortunately for the person searching endlessly for this error it's not a standard Oracle offering. Instead, it's a user-defined exception/error number to catch and report any of a plethora of unnamed Oracle exceptions, which makes finding a definitive answer for what this error represents practically impossible, as it means what the application programmer intended, which can, and does, vary between application programmers and applications. Let's look at the valid range of user-definable error numbers/exceptions and try to clear the clouded air a bit. Oracle offers a range of error numbers which are not assigned any standard Oracle error text and are not associated with any fixed Oracle exceptions; this range starts at 20000 and ends at 20999. Looking at a basic PL/SQL block to define and use some of these available error numbers it can be seen that these can either be quite useful or quite frustrating: SQL> -- SQL> -- User defined errors are numbered SQL> -- from 20000 to 20999 inclusive SQL> -- SQL> -- SQL> -- Any time you see an error number SQL> -- in that range it's an exception/error SQL> -- defined by the user SQL> -- SQL> SQL> declare 2 ex20000 exception; 3 ex20459 exception; 4 ex20773 exception; 5 ex20999 exception; -- a very popular error number 6 7 pragma exception_init(ex20000, -20000); 8 pragma exception_init(ex20459, -20459); 9 pragma exception_init(ex20773, -20773); 10 pragma exception_init(ex20999, -20999); 11 12 begin 13 begin 14 begin 15 begin 16 17 -- 18 -- Raising our first defined exception 19 -- 20 raise ex20000; 21 22 exception 23 when ex20000 then 24 25 -- 26 -- Return the first error code 27 -- and where we generated it 28 -- 29 dbms_output.put(dbms_utility.format_error_stack); 30 dbms_output.put_line(' First error'); 31 dbms_output.put_line(dbms_utility.format_error_backtrace); 32 33 end; 34 35 -- 36 -- Raise the second defined error 37 -- 38 raise ex20459; 39 40 exception 41 when ex20459 then 42 43 -- 44 -- Return the error code 45 -- and where we generated it 46 -- 47 dbms_output.put(dbms_utility.format_error_stack); 48 dbms_output.put_line(' Second error'); 49 dbms_output.put_line(dbms_utility.format_error_backtrace); 50 51 end; 52 53 -- 54 -- Ra