Try to catch as the exception handling in Pl/Sql

In a procedure, I want to do 1 logical unit, is not serious if it fails, execute the logic unit 2

This seems to be a typical scenario of try-catch. But how can I do it in pl/sql?

create or replace
PACKAGE BUILD_PKG
AS
PROCEDURE reset_seq_and_truncate_tbl(
  p_seq_name 
IN VARCHAR2,
  p_table_name
IN VARCHAR2 );
END BUILD_PKG;
/
create or replace
PACKAGE BODY BUILD_PKG
AS
BEGIN
PROCEDURE reset_seq_and_truncate_tbl(
  p_seq_name 
IN VARCHAR2,
  p_table_name
IN VARCHAR2 )
IS
  l_val NUMBER
;
BEGIN
  
BEGIN
  
EXECUTE immediate 'truncate table ' || p_table_name;
  EXCEPTION
  
WHEN OTHERS
  
THEN dbms_output.put_line(SQLCODE);
  
END;

  
BEGIN
  
EXECUTE immediate 'alter sequence ' || p_seq_name || ' increment by 1 minvalue 0';
  EXCEPTION
  
WHEN OTHERS
  
THEN dbms_output.put_line(SQLCODE);
  
END;
END reset_seq_and_truncate_tbl;

END BUILD_PKG;

Try below

PROCEDURE reset_seq_and_truncate_tbl(
  p_seq_name  IN VARCHAR2,
  p_table_name IN VARCHAR2 )
IS
  l_val NUMBER;
BEGIN
   BEGIN
   EXECUTE immediate 'truncate table ' || p_table_name;
  EXCEPTION
   WHEN OTHERS
   THEN dbms_output.put_line(SQLCODE);
   END;

BEGIN
   EXECUTE immediate 'alter sequence ' || p_seq_name || ' increment by 1 minvalue 0';
  EXCEPTION
   WHEN OTHERS
   THEN dbms_output.put_line(SQLCODE);
   END;
END reset_seq_and_truncate_tbl;

Tags: Database

Similar Questions

  • Exception handler, not shot context except for the Subscriber to events

    Hello

    Is it possible to make the activity of the exception handler when an exception is thrown by the Subscriber to the contextual events?

    In my application, as well a parent workflow and a child task flow (a task with fragments of page that is inserted into the parent company) have some activity of the exception handler.
    When an exception is thrown by one method other than the Subscriber to contextual events (for example, the action listener), the activity of the exception handler is triggered as expected.
    However, when the parent task flow publises a contextual event which is underwritten by the child workflows and the Subscriber throws an exception, the exception handler is triggered neither the parent nor the child workflows.

    Any help is appreciated.

    Thank you
    Kenji

    Hello

    function when the exception is thrown. The ADFc exception handler does not fire for exceptions that occur during the RENDER_RESPONSE phase (so it is one thing to check). In this case you must use a try-catch block. It also depends on what is exactly raining the exception (e.g. What is the bean of the code where the Manager, or a problem on the producer, is the involved link layer, etc.).

    Frank

  • Global exception handler

    Hello guys,.

    I'm trying to implement a handler for global exception (https://blogs.oracle.com/jdevotnharvest/entry/extending_the_adf_controller_exception_handler) by extending oracle.adf.view.rich.context.ExceptionHandler class and put the fully qualified name of the class that is implemented in the file .adf/META-INF/services/oracle.adf.view.rich.context.ExceptionHandler.txt .

    I see that it works locally jDeveloper (Studio Edition Version 11.1.1.6.0) when the built-in but server deployment does not work when it is deployed to the server of a dev... I see the folder has been created in the tmp folder in dev server and the file is there, not sure what else to try. Please help.

    Thank you

    Aerts

    OK finally solved! It was with the declaration of .adf/META-INF/services record - it seemed when the exception handler server deployment was not get registered. To debug the registered services, you must use the following.

    
              ServiceLoader compilers = ServiceLoader.load(ExceptionHandler.class);
                _logger.info(compilers.toString());
    
                for (ExceptionHandler compiler : compilers) {
                    _logger.info("******ExceptionHandler*********" + compiler);
                }
    

    If you check the loggers, the exception handler should be listed, otherwise then create a jar file with the class of exception handler and to put the issue of services along - with the file of exception handler (not a text file) within the META-INF of the jar file. Last step - put the jar file in WEB-INF/lib in your controller project.

  • Taskflow exception handler issues

    Hi all

    We have an ADF application deployed on Weblogic in Dev environment. A taskflow based on human labor BPM has a "ExHandler" view activity like exception handler. To test this, I inserted a "Dummy" dummy activity without application and navigation added to this activity of landing page "landing". When I tested this application flow correctly is the activity of the "ExHandler" exception exception handler.

    In another environment, the server is led by SST in SSO. When I tested the same scenario now, I get a 404 error instead of the activity of the exception handler. I captured the URL to which the request happens using a violin. The URL seems to be legitimate, because it is the same URL that I see in the Dev environment.

    In the OHS access history, I see two requests to "ExHandler".

    The first is a 302 with adf control state identical to that landing page "landing".

    Second, one is a 404 error with a different value for the adf State.

    All the world is facing this issue before? I got no idea about it. Any help is appreciated.

    JDev / ADF 11.1.1.7

    WebLogic - 10.3.6

    Kind regards

    SAI

    Problem solved. It was with cookie JSESSIONID. BPM human task URL is also a culprit (I should have checked that first). I gave the host name in the format "abc" instead of the full name of "abc.def.xyz". Although it works perfectly fine for normal scenarios, the issue does surface when I used the workflow exception handler activity. Initial demand was going on the 'abc' host, which created a JSESSIONID cookie. Later, when control is transferred to the exception handler activity, the request goes to 'abc.def.xyz' host. It resulted in creating new JSESSIONID by the system.

    I replaced the host name with "abc.def.xyz" instead of "abc", and this fixed the problem.

    Timo Hahn Thanks for your advice. I created a sample application and cannot reproduce the problem. Then I checked again carefully queries Fiddler and found the issue.

    Kind regards

    SAI

  • Continue the block after the exception management

    The guys in the slot block.

    create or replace procedure proc_case
    (p_in IN number)
    is
    begin
    case p_in
    when 1 then
    dbms_output.put_line('its one'); 
    when 2 then
    dbms_output.put_line('its two'); 
    end case;
    dbms_output.put_line('after the exception handler'); 
    exception when case_not_found then
    dbms_output.put_line('its not found'); 
    end;
    

    When the procedure is executed as follows.

    begin
    proc_case(3);
    end;
    

    It shows the statement in the block of exception, but after that it does not run the statement following the exception handler and the outputs of the block, how can I execute the statement after the end case statement. I do not use the Else statement in case because I wanted to understand the logic of this block.

    CREATE OR REPLACE

    PROCEDURE proc_case

    (

    p_in in NUMBER)

    IS

    BEGIN

    BEGIN

    P_in CASE

    WHEN 1 THEN

    dbms_output.put_line ('the one');

    WHEN 2 THEN

    dbms_output.put_line ('two');

    END CASE;

    EXCEPTION

    WHEN case_not_found THEN

    dbms_output.put_line ("' its not found");

    END;

    dbms_output.put_line ("' after the exception handler");

    END;

  • cursor for loops with exception handling

    Hi all

    I use oracle11g I need to write a stored procedure to about 10 select statements with the managements of exceptions for each select statement. I am unable to handle the exception handling.please guys help

    Here is the code sample I wrote

    CREATE OR REPLACE PROCEDURE TEST_PROC

    (P_ID IN VARCHAR2,

    P_MOB IN VARCHAR2,

    P_OUT_MSG OUT VARCHAR2)

    AS

    CURSOR CUR_RES AS SELECT NAME, INFO, VER_DETAILS FROM TABLE_NAME WHERE ID = P_ID AND MOBILE_NO IS P_MOB;.

    BEGIN

    FOR REC IN CUR_RES LOOP

    P_OUT_MSG: = 'BKY000. '

    END LOOP;

    EXCEPTION

    WHEN NO_DATA_FOUND THEN

    P_OUT_MSG: = 'BKY001. '

    END;

    OUTPUT DESIREE WHILE RUNNING IN A JAVA APPLICATION IS REQUIRED

    IF THE DATA FOUND BKY000 | RESULT OF THE SELECT STATEMENT

    IF DATA NOT FOUND BKY001

    PLEASE HELP WITH SAMPLE... PLEASE FRIENDS

    It's more clear now

    create or replace procedure test_proc (p_id in varchar2, )

    p_mob in varchar2,

    p_out_msg out varchar2,.

    p_result on sys_refcursor

    ) as

    v_err_msg varchar2 (300);

    row_count number;

    no_data_returned exception;

    nonunique_column exception;

    Start

    Open Select p_result *.

    WCP

    where deptno = to_number (p_id)

    and job = p_mob;

    Select count (*)

    in row_count

    WCP

    where deptno = to_number (p_id)

    and job = p_mob;

         

    If row_count = 0 then

    raise no_data_returned;

    end if;

    Select keep max (count (*)) (dense_rank first order by Count)

    in row_count

    from (select *)

    WCP

    Union all - simulating a duplicate line

    Select 7839, "ETBIN', 'PRESIDENT', null, trunc (sysdate), 3000, null, 10

    of the double

    )

    where deptno = to_number (p_id)

    and job = p_mob

    Group by empno

    view count (*) > 1;

    If row_count > 1 then

    raise nonunique_column;

    end if;

    p_out_msg: = 'BYK0000 ';

                       

    exception

    When no_data_returned

    then p_out_msg: = "BYK001";

    When nonunique_column

    then p_out_msg: = "BYK002";

    while others

    then v_err_msg: = ' procedure TEST_PROC: error: ' | SQLCODE. ': ' || substr (SQLERRM, 1, 200);

    raise_application_error(-20000,v_err_msg);

    end;

    declare

    R_C sys_refcursor;

    E_r emp % rowtype;

    E_m VARCHAR2 (255);

    DEPTNO number: = 10;

    VARCHAR2 (30) employment: = "PRESIDENT";

    Start

    dbms_output.put_line (' input parameters: deptno = ' | to_char (deptno) |) '; job = ' | Job);

    test_proc (to_char (DEPTNO), Job, E_m, R_C);

    dbms_output.put_line (' result: ' | e_m);

    If e_m = "BYK0000" then

    loop

    extract r_c in e_r;

    When the exit r_c % notfound;

    dbms_output.put_line (to_char (E_r.empno) |' |) '|| RPAD(E_r.Ename,10) |' | '|| RPAD(E_r.job,10) |' | '|| TO_CHAR (E_r.SAL, 'fm99990'));

    end loop;

    end if;

    exception

    While other then dbms_output.put_line ('exception: ' | sqlcode |) ': ' || substr (SQLERRM, 1, 200));

    end;

    input parameters: deptno = 10; job = PRESIDENT

    result: BYK002

    Statement processed.

    Concerning

    Etbin

  • Task workflow exception handler

    Hi all

    I'm trying to specify a method activity in an exception handler in the adfc-config. The problem is that if I specify a view activity or a workflow bounded as the exception handler then, it works very well, but if the exception handler is a method, then it is not recognized. What could be the cause? I need execute a method when an exception occurs.

    Version: 11.1.2.0

    Published by: NewBee on April 23, 2013 10:37

    Hello

    It should not be a problem with that and I recently did the same thing with JDeveloper 11 g R2 (do not know which version of JDeveloper you use because you did not share this information). I guess you checked only the activity of the method as an exception without any other configuration handler? If so, then set a breakpoint in the method managed bean that you access from the activity of the method to see if it actually stops. Also note that not all exceptions are handled by the controller exception handler. For example an exception during rendering of phase response (generally an exception in a bean managed) is not managed by the controller. You should also avoid the managed bean that handles the exception to throw a. This however you will see when you debug the bean.

    Frank

  • The exception question

    Hi all

    I wrote a simple exception in the procedure.
    I say if this procedure worked for a very long time and I decided to kill the process, the exception will manage these unexpected process
    for example, coding,.

    Begin
    .
    .
    EXCEPTION when others then
    dbms_out.put_line ('unexpected end');
    end;

    TJ_Tay wrote:
    Hi all

    I wrote a simple exception in the procedure.
    I say if this procedure worked for a very long time and I decided to kill the process, the exception will manage these unexpected process
    for example, coding,.

    Begin
    .
    .
    EXCEPTION when others then
    dbms_out.put_line ('unexpected end');
    end;

    I guess you mean kill the session when you say that you kill it... in which case, NO, the exception handler does capture because the session has ended.
    In addition, an exception WHEN OTHERS is not a good idea because it often masks the exceptions that you were not pregnant.

    You're just write exception handlers for things that you expect to arrive.

  • ExceptionHandler implementation and activity marked as 'exception handler.

    Hello

    Please consider this sample application created using JDeveloper 11.1.1.3.0
    at http://www.consideringred.com/files/oracle/2010/CombinedExceptionHandlerApp-v0.01.zip

    It has an implementation of the ExceptionHandler configured in a services configuration file and config file adfc. XML that unbound the task path has a view activity "exceptionHandlerPage" marked as "exception handler.

    -scenario (sc1)
    Run the page browseDepartments.jspx and click on the button 'make throwMyViewRuntimeExceptionAction', resulting in a dialog box showing a FacesMessage created in MyViewExceptionHandler.handleException (), as shown in the screenshot CEHApp-001-sc1 - dialog.png.

    -scenario (sc2)
    Change the contents of the «.adf\META-INF\services\oracle.adf.view.rich.context.ExceptionHandler file"in a class name unknown, for example,"MyViewExceptionHandler"to"UnknownMyViewExceptionHandler ". (causing a java.lang.ClassNotFoundException when execution and application of ExceptionHandler therefore actually not custom configured)
    Run the page browseDepartments.jspx and click on the button 'make throwMyViewRuntimeExceptionAction', with the 'exceptionHandlerPage', showing the result of the EL expression result #{controllerContext.currentViewPort.exceptionData}, as shown in the screenshot CEHApp-001-sc2 - page.png.

    Based on the scenario (sc1) and (sc2), it looks like an implementation of the ExceptionHandler configured in a configuration file of services takes precedence over an activity in the boundless task marked as '' Manager exceptions '' flow.

    question:
    -(q1) is it expected behavior that an implementation of the ExceptionHandler configured in a services configuration file overrides an activity in the stream of boundless task marked as 'exception handler?

    Thank you very much
    Jan Vervecken

    Jan,

    Yes. Actually, the exception handler is called instead of the default AdfcExceptionHandler, which is the implementation that makes the activity of the labour exception handler. If you handle an exception in your custom exception handler class, up the machine again and the default mechanism is used.

    Frank
    PS. : If we woul do the opposite so you won't be able to change the behavior of management at all ;-) exceptions

  • on exception handling in function, while using this function in sql

    Hi gurus,

    I have a question concerning the registration of exceptions when using functions.

    I wrote a separate package to handle errors, where I have a procedure.
    In this process, I connect my error in a table and then triggers the error on the front end.
    Ex:
    proc_log_and_raise    -- this proc... inserts my error into a table and then raise
    now, I have included this error procedure in all functions and procedures.

    Consider an example with an example of procedure and function.
    function func_1(( v_var   varchar2) return varchar2 is
    begin
         select   column2
         from     table2
        where col1 = v_var;
    exception 
        when others then 
             proc_log_and_raise;
    end;   
    procedure proc_1( v_var   varchar2) is
    begin
        select   func_1(v_var)  -- error occurs here..
        from     table_a
        where   col1 = v_var;
    exception 
        when others then 
             proc_log_and_raise;
    end;    
    now I do
    exec  proc_1( v_var );
    but now my problem is, when an error occurs in func_1, I get an error with the DML operation (as we are inserted in the table of errors)
    ORA-14551: cannot perform a DML operation within a query.

    So what I want to do, connect the two functions and procedure where the error occurred.

    So is it better otherwise, we can write our exception handling, so that I could mistake the newspaper and use the function in a select statement.

    Thank you.

    A small example of using autonomous transactions

    create table error_log (error varchar2(4000));
    
    Table created.
    
    SQL> create procedure log_error(p_error in varchar2) as
      2  pragma autonomous_transaction;
      3  begin
      4  insert into error_log values (p_error);
      5  commit;
      6  end;
      7  /
    
    Procedure created.
    
    SQL> create function will_fail return number as
      2  begin
      3  for x in (select 2/0 from dual) loop
      4  null;
      5  end loop;
      6  exception
      7  when others then
      8  log_error(sqlerrm);
      9  raise;
     10  end;
     11  /
    
    Function created.
    
    SQL> create procedure call_will_fail as
      2  begin
      3  for x in (select will_fail from dual) loop
      4  null;
      5  end loop;
      6  end;
      7  /
    
    Procedure created.
    
    SQL> exec call_Will_fail;
    BEGIN call_Will_fail; END;
    
    *
    ERROR at line 1:
    ORA-01476: divisor is equal to zero
    ORA-06512: at "WILL_FAIL", line 9
    ORA-06512: at "CALL_WILL_FAIL", line 3
    ORA-06512: at line 1
    
    SQL> select * from error_log;
    
    ERROR
    -----------------------------------------------------------------
    ORA-01476: divisor is equal to zero
    

    Note that the recovery is carried out by the exception handler.

  • Exception handler

    I received an error ORA 00001, DUP_VAL_ON_INDEX, when you run the script below.

    I think I have just a few bad data in the table. Can i:
    1. grasp the line where incorrect data to? or
    2 ignore the error so that the script will not bomb?

    OR 3. How can I get the clause to the work of handling exceptions?

    I'm updating 249 000 rows in a table and 6000 lines have been updated before the failure.
    after I received the error message, I tried to add the Exception Handling clause.

    DECLARE

    Cursor SSN_C IS
    Select pidm, spid spriden.spriden_id spriden.spriden_pidm
    of saturn.spriden spriden
    where spriden.spriden_id like '% A0 ".
    and spriden.spriden_change_ind is null
    - and spriden.spriden_pidm = 22000
    and exists (select * from saturn.spriden one)
    where upper (a.spriden_id) = lower (a.spriden_id)
    and a.spriden_pidm = spriden.spriden_pidm);
    BEGIN
    FOR x in SSN_C
    LOOP
    When the output SSN_C % Notfound;
    Update saturn.spriden b
    Set b.spriden_id = x.spid
    where b.spriden_pidm = x.pidm
    and b.spriden_id <>x.spid;
    Commit;
    END LOOP;
    END;


    / * exception
    WHEN DUP_VAL_ON_INDEX
    THEN null; */


    *************
    Background:
    What I'm trying to do, is replace the SSN in a field. The table has a unique ID called a pidm and there a field ID. Everyone pidm has two rows, one with a SSN in the ID field and the other with a BETTER and unique ID. I want to copy the ID and replace the SSN.

    Hello

    Have you tried with the table to the error log I posted in my previous post or you did it without him? Error log must capture the majority of the DML error. What is the error exactly are you? Can you post error with your pl/sql block (entire block)?

    Concerning

  • Try to handle the exception of another block, do not get it... Precious need help please...

    Hi, fields,

    I want to RAISE an exception through my first procedure and want to manage it in the second procedure. [I think it's concept of reproduction or multiplication exception].

    Not able to do, need your valuable advice.


    create or replace procedure test_excep1 (a number, b number)
    is
    c number;
    external_exception exception;
    Start
    c: = a / b;
    dbms_output.put_line ('Came out' | c);
    exception
    When zero_divide then
    raise external_exception;
    end;

    Start
    test_excep (2,0);
    end;

    When executing procedure above with divisor of zero, I get the error message below

    ORA-06510: PL/SQL: not supported by the user-defined exception
    ORA-06512: at "SONARDBO. TEST_EXCEP', line 10
    ORA-01476: divisor is equal to zero
    ORA-06512: at line 2


    Now if I try to catch this exception by another procedure, it does not help me. -This is my exact requirement.


    Create procedure test_excep2 (in numbers, number e d)
    is
    external_exception exception;
    Start
    test_excep (d, e);
    exception when external_exception then
    dbms_output.put_line ("' work of exception management");
    end;

    Start
    test_excep2 (2,0);
    end;

    When running over block, get the message below.

    ORA-06510: PL/SQL: not supported by the user-defined exception

    ORA-06512: at "SONARDBO. TEST_EXCEP', line 10

    ORA-01476: divisor is equal to zero

    ORA-06512: at "SONARDBO. TEST_EXCEP2', line 5

    ORA-06512: at line 2

    Thanks a ton in advance for help.

    Everything simply because you called an undefined exception 'external_exception' in a unit of code, and then reuse the name in another--does not mean that the variables of these exceptions are for the same exception. Common names mean nothing in this case. Using the same name for the variables or constants and exceptions across modules/units of code, does not mean that they are now the same.

  • Catch the Exception and continue

    Hello

    If the exception was framed but would like to continue anyway to another step (for example, Insert statement or create index)

    < pre >
    sql_stmt1: = 'DROP INDEX PRD_GLO_SDX;
    EXECUTE IMMEDIATE sql_stmt1;
    EXCEPTION
    WHILE OTHERS THEN
    raise_application_error (-20001, SQLERRM |) » '||' CANNOT DELETE THE INDEX OF PROBABILITY THAT THE INDEX MAY NOT EXIST");
    < / pre >

    Can anyone give advice on continue even if there is an exception?

    See you soon.

    do not raise the exception, if you do not want.

    sql_stmt1  :='DROP INDEX PRD_GLO_SDX';
      EXECUTE IMMEDIATE sql_stmt1;
       EXCEPTION
                WHEN OTHERS THEN
    --               raise_application_error(-20001,SQLERRM||' '||'PROBABLITY INDEX CANT BE DROPPED AS INDEX MAY NOT EXIST');
    null;
    

    It is best to use a specific error to handle instead of the "catch-all", SO that OTHERS

  • Defined by the user exception handling

    Hello

    version Oracle 11.1.0.7

    Question 1:
    I just want to know what is the difference between the methods for using user-defined exceptions.

    Method 1: don't need initialization exception
    create or replace procedure p1
    as
    exc_p1 exception;
    begin
     do something .... 
     -- fails
     Raise exc_p1;
     exception when exc_p1 then
     raise;
     end;
     
    Method 2: use initialization exception
     create or replace procedure p2
     as
    exc_p2 exception;
    prgma exception_init(exc_p2,-20999);
    begin 
    p1;
    exception
    when exc_p2 then 
    raise;
    end;
    Question2

    Please let me know when and where to use these user-defined functions and I read the comments of Tom kyte on the use then than others, then raise or raise_application_error
    exception management. Rather than use the raise or raise_application_error can I use "dbms_output.put_line (dbms_utility.format_error_backtrace); dbms_output.put_line (dbms_utility.format_error_stack)) 'or can I do the exceptions as handler below.
    " when others then 
    raise_application_error(-20001,'error in p1  '||dbms_utility.format_error_backtrace ||dbms_utility.format_error_stack); " 
    Thank you
    Mike

    Mike wrote:
    Hello

    version Oracle 11.1.0.7

    Question 1:
    I just want to know what is the difference between the methods for using user-defined exceptions.

    Method 1: don't need initialization exception

    create or replace procedure p1
    as
    exc_p1 exception;
    begin
    do something ....
    -- fails
    Raise exc_p1;
    exception when exc_p1 then
    raise;
    end;
    

    Method 2: use initialization exception

    create or replace procedure p2
    as
    exc_p2 exception;
    prgma exception_init(exc_p2,-20999);
    begin
    p1;
    exception
    when exc_p2 then
    raise;
    end;
    

    The first method is used when you plan to raise user-defined errors by using the name, and user-defined errors are raised in the procedure you capture them.

    The second method is used when you want to capture a specific error number, it's an error specific oracle (one that has not already been appointed) or a user defined error. In your example procedures, if we show what exceptions occur by putting in the debugging...

    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace procedure p1 as
      2    exc_p1 exception;
      3  begin
      4    Raise exc_p1;
      5  exception when exc_p1 then
      6    dbms_output.put_line('P1:exc_p1');
      7    raise;
      8* end;
    SQL> /
    
    Procedure created.
    
    SQL>
    SQL> create or replace procedure p2 as
      2    exc_p2 exception;
      3    pragma exception_init(exc_p2,-20999);
      4  begin
      5    p1;
      6  exception
      7    when exc_p2 then
      8      dbms_output.put_line('P2:exc_p2');
      9      raise;
     10    when others then
     11      dbms_output.put_line('Other exception');
     12      raise;
     13  end;
     14  /
    
    Procedure created.
    
    SQL> set serverout on
    SQL> exec p2;
    P1:exc_p1
    Other exception
    BEGIN p2; END;
    
    *
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SCOTT.P2", line 12
    ORA-06512: at line 1
    

    ... we can see that the captured P1 procedure an exception defined by the user by his name, but procedure P2 could only recognize as being a mistake 'OTHERS '.

    But if P1 were to raise a specific error number...

    SQL> create or replace procedure p1 as
      2    exc_p1 exception;
      3  begin
      4    Raise exc_p1;
      5  exception when exc_p1 then
      6    dbms_output.put_line('P1:exc_p1');
      7    raise_application_error(-20999,'Procudure 1 error raised',true);
      8  end;
      9  /
    
    Procedure created.
    
    SQL> exec p2;
    P1:exc_p1
    P2:exc_p2
    BEGIN p2; END;
    
    *
    ERROR at line 1:
    ORA-20999: Procudure 1 error raised
    ORA-06512: at "SCOTT.P1", line 7
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SCOTT.P2", line 9
    ORA-06512: at line 1
    
    SQL>
    

    ... then because P2 is looking for this under his own name of exp_p2 error number, he seized the exception thrown by P1 as is exp_p2 exception.

    Now, just to complete the example...

    SQL> create or replace procedure p1 as
      2    exc_p1 exception;
      3    pragma exception_init(exc_p1,-20999);
      4  begin
      5    Raise exc_p1;
      6  exception when exc_p1 then
      7    dbms_output.put_line('P1:exc_p1');
      8    raise;
      9  end;
     10  /
    
    Procedure created.
    
    SQL> exec p2;
    P1:exc_p1
    P2:exc_p2
    BEGIN p2; END;
    
    *
    ERROR at line 1:
    ORA-20999:
    ORA-06512: at "SCOTT.P2", line 9
    ORA-06512: at line 1
    

    ... P1 has now associated with error number 20999 is exc_p1 exception, when he simply raises this exception is triggered 20999 error number. P2 is unable to capture under the name of exc_p1 because this exception name does exist in the process of P1, but because P2 seeks 20999 under his own name of exc_p2 exception, it manages to capture him.

    So, to summarize, the name of the exception without the pragma is allowed to handle exceptions as part of the same name, but if you need capture outside the scope, you use the pragma to assign a number to it-specific exception.

    Question2

    Please let me know when and where to use these user-defined functions and I read the comments of Tom kyte on the use then than others, then raise or raise_application_error

    User-defined exceptions are used mainly to treat logic errors. The key is the word "handful." If you can handle an exception (i.e. to do something) you should capture it and do what needs doing. If you can't handle it then, you have to trigger it.
    Using a then "than others' exception should be a last resort. In general, you only manage exceptions that you plan to arrive. One then "than others' captures all exceptions that have not already been dealt with. If you have an exception "while others" and you do not throw the exception upward once again, then effectively hide you any errors to get noticed (errors are still happening, but you are not aware of them except for the fact that your "code does not work" or "data is not correct"). The only time you would really use one then "than others' exception would be if you need to connect all the errors in a table, but then after the cut, which should continue to be the exception to the calling code.

    exception management. Rather than use the raise or raise_application_error can I use "dbms_output.put_line (dbms_utility.format_error_backtrace); dbms_output.put_line (dbms_utility.format_error_stack)) 'or can I do the exceptions as handler below.

    " when others then
    raise_application_error(-20001,'error in p1  '||dbms_utility.format_error_backtrace ||dbms_utility.format_error_stack); " 
    

    You should not use dbms_output.put_line, except for the purpose of debugging. To use that assumes that the output of the server is catches or displayed, which, if it is a backend process, it won't. The correct way to error log is a table, or at worst a file on the server.

    If you need generate an application error and you want to keep the stack error, you just need the third parameter set to TRUE.

    raise_application_error({errornumber},{message},true);
    
  • "evaluations thread jdi" has encountered a problem. Queue of the async thread exception handling.

    I'm trying to debug a java application on the Blackberry Pearl, using Eclipse v3.4.1. After the break on a line of code, I chose a variable in the 'Variables' tab and the following message appeared:

    "evaluations thread jdi" has encountered a problem.

    Queue of the async thread exception handling. java.lang.NullPointerException.

    java.lang.NullPointerException

    What kind of message is this, she comes from - and knowledge where I even begin to determine why this is happening. Perhaps can someone point me in the right direction.

    Thank you

    Steve

    Object that you are trying in this instance is Null.

Maybe you are looking for

  • Password photo on Twist

    anyone is able to use the photo their turn password? I don't seem to have that option.

  • Argus and Apple Watch

    How can I sync my Apple Watch with the app argus health and fitness?  I checked with the argus and have a page on what he can do, but can't find the instructions on syncing.

  • Do I really need these on my PC?

    MS User-Mode Driver Framework Feature Pk 1.0 Windows Powershell (TM) 1.0 MSXML 4.0 SP2 and MSXML 6 SP2 ATI Display Driver I'm remove as many programs that I can and don't know if I should remove them. I have Windows XP SP 3 and gave me my turn, so I'

  • Impossible to reinstall Itunes and quickplayer due to a msi windows error.

    I tried many things- -Install the updated release of windows msi 4.5 -clear all temporary directories -clear manually flying over ITunes folders and quickplayer Msi - MS uninstall -Registry cleaner

  • Creen computer turned on its side! Help!

    My husbands computer on his laptop computer screen has turned sideways and we do not know how to fix it! Help, please! It is also inh safemode and do not know what to do.