This discussion is archived
4 Replies Latest reply: Feb 19, 2013 5:18 AM by Patrick Wolf RSS

Differences in Exception Handling between 3.2 and 4.x

HarryF Newbie
Currently Being Moderated
This code behaves differently in 3.2 and 4.2. In 3.2 I see "My Exception". In 4.2 I see "User-Defined Exception". I left the success and failure message blank for the process. I am trying to understand what I am supposed to do to get my custom error message displayed.

declare
e_exception exception;
begin
raise e_exception;
exception
when e_exception then
apex_application.g_print_success_message := 'My Exception';
raise;
end;
  • 1. Re: Differences in Exception Handling between 3.2 and 4.x
    scott.wesley Guru
    Currently Being Moderated
    Do you need the "raise;"
  • 2. Re: Differences in Exception Handling between 3.2 and 4.x
    HarryF Newbie
    Currently Being Moderated
    yes, raise is needed. otherwise APEX thinks the procedure completed successfully.
  • 3. Re: Differences in Exception Handling between 3.2 and 4.x
    scott.wesley Guru
    Currently Being Moderated
    I'm just suggesting that's perhaps why you don't see the "success_message", since you've propagated the exception.

    Without knowing context of what you're trying to attempt, it's hard to suggest the best course of action.
  • 4. Re: Differences in Exception Handling between 3.2 and 4.x
    Patrick Wolf Employee ACE
    Currently Being Moderated
    Hi Harry,

    apex_application.g_print_success_message will/should only be used if your processes/page completes successfully, so it can't really be used for this use case. BTW, that global variable isn't really documented and not supported by us. If you want to raise an exception in your process which should stop execution of your process/page accept, I would suggest to use RAISE_APPLICATION_ERROR instead.
    declare
       e_exception exception;
    begin
       raise e_exception;
    exception
       when e_exception then
           raise_application_error(-20000, 'This custom account is not active!');
    end;
    If you don't like that the user sees the ORA-20000 in your error message, I would suggest to have a look at our error handling function example at http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35127/apex_error.htm#CABDJBGJ (the code to look for is apex_error.get_first_ora_error_text). Also have a look at my blog posting at
    http://www.inside-oracle-apex.com/apex-4-1-error-handling-improvements-part-1/ and http://www.inside-oracle-apex.com/apex-4-1-error-handling-improvements-part-2/ how to use it and how to change your process so that the error is displayed inline.

    Regards
    Patrick
    -----------
    My Blog: http://www.inside-oracle-apex.com
    APEX Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points