Generic Exception Handler/Listener

All,
I have a web application and I want to create a generic exception handler/listener which will listen to all the exception(checked and runtime) which are thrown by web application.
Any idea how can I do this?
Regards.

797836 wrote:
Hi,
I want to build a generic exception handler which can be reused in any java j2ee applications. Unlikely. Probably impossible.
I have java application which is communicating with other 3rd party applications like webservices, webmethods , etc from where we are getting an errorcode which will be used in our java application to do a lookup to get the respestive error message from the resource bundle. Please clarify in such case how I can go with a generic exception handler which will be build separately and will be integrated with Java applications to handle the exceptions and errors.An excellent example of why a universal exception handler wouldn't work.
At some point a call tree looks like A->B->C, where C (or beyond) that is where your communications problem occurs. The impact of that depends on the application.
For example if a user types in a url (at A) and the server (C) fails to resolve it then that is a user problem.
However if nightly batch process expects to download an update file every night from one location and it can't connect then that is an operations error (or notification/alert.)

Similar Messages

  • Generic Exception handler in java

    We have developed a client java application with our own exception hierarchy derived from java.lang.exception. We raise our own exception in case of error scenarios. But there is one additional thing which we want to do:
    1. When ever any exception is raised in our exception we want to do some generic exception handling (like kicking of some module which collects the log files and send it to the administrator.
    2. We want the above activity to happen also when any runtime exception is raised. We are not catching any runtime exception and we have no handle for this.
    How should we go about this. Can we write a very low-level generic exception handler?
    We do not want to have done at every catch block we have in our code. I mean we want to have some hook at a very generic place.
    Let me know if some body can be help me on this.

    As far as I know, for exceptions that are caught, you must make a call to a generic handler in the catch block, or you may rethrow the exception as a RuntimeException, and let it propagate.
    For RuntimeExceptions and Errors in threads that you create, the easiest way to solve this is to subclass ThreadGroup, override uncaughtException with the appropriate code, and create all your threads in this group. For a thread like main, have the first thing in the thread be the creation of a new thread in the new group, then pass control to that thread. For fixed threads, like the event queue, someone had a suggestion already. Note that uncaughtException is only called just before the thread ends, so an exception that shouldn't end the thread should be handled seperately.

  • Generic Exception Handling

    Im trying to get a solution done on generic runtime exception handling.
    What kind of possibilities do i have to have a generic solution done in JSF, without forcing my
    Managed Beans to handle runtime exceptions.
    As JSF has different phases and each phase would be forced to catch those runtime exceptions,
    it seems to be difficult to me...
    The idea would be like:
    try{
    doRender()/doAction()/doValidate() etc ...
    }catch(Exception e){
    // do something and put a message to FacesContext
    Edited by: nailuenlue on Dec 4, 2008 11:23 AM

    Yeah! I know the difference between chacked ans uncheked exceptions, and how sprign work with exceptions. This is the reason for my comments and suggestions.
    I think you don`t understand me, and because hope is not enough I try to explain me (maybe help others):
    1.- <error-page> not only work with http errors headers as 404, you can specify a java exception including Exception
    2.- In a Servlet you can do wath you need as: send an email or a mobile message to Admin staff, redirect, forward, log or wathever you need. (I think is more than only show an error message).
    <error-page>
      <exception-type>java.lang.Exception</exception-type>
      <location>/yourServlet</location>
    </error-page>By the other hand I can tell you that JSF implement MVC, then JSF need a front controller (the C of MVC), you canf find it into web.xml descriptor, something like this:
    <servlet>
      <servlet-name>Faces Servlet</servlet-name>
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>*.jsf</url-pattern>
    </servlet-mapping> Yeah! the controller is a servlet. you can try to extend this class and overwrite some methods.

  • Exception handling - Common exception handling framework

    Hi,
    I need to come up with a common exception handling framework in an environment where ESB and ODI are being used for interfacing and ELT operations. I am of the opinion that
    1. A generic exception handling framework can be built using BPEL and can be invoked from ESB. Is my understanding correct?
    2. Are there any ways that we can build this framework using ESB itself? I opinion that it's not possible as there is no concept of try-catch?
    3. I am not able to find any documentation wrt exception handling when ODI is used? Can some one help me with some pointers?
    4, When I come up with a common exception handling framework, will I be able to invoke the same from ODI.
    Thanks,
    Mahesh

    Thanks for the reply Allan. I haven't used BusinessWorks.
    I did go through this thread before and here's my understanding.
    1. ESB provides the ability of error handling (client management API) but not the exception handling i.e. I can't redirect the flow in case there is an exception in my primary flow. Am I right with my understanding?
    2. Error handling ability of ESB is limited to retryable exceptions viz-a-viz asynchrounous ESB processes (e.g. database listener not up) where in the process can be retried. Am I right here?
    Thanks,
    Mahesh

  • Generic Exception Handeling

    I need the executed SQL and variables with my error. I got this far:
    <code>
    PROCEDURE error_mail IS
    pMessage VARCHAR2(2000);
    pSender VARCHAR2(80) := '[email protected]';
    pRecipient VARCHAR2(80) := '[email protected]';
    pSubject VARCHAR2(80) := 'Error Package : LGX_P_ANIM';
    mailhost CONSTANT VARCHAR2(30) := 'mail.home.co.za';
    crlf CONSTANT VARCHAR2(2):= CHR(13) || CHR(10);
    mesg VARCHAR2(1000);
    mail_conn utl_smtp.connection;
    l_str VARCHAR2(255);
    BEGIN
    select substr(sql_text,1,255) into l_str from sys.V_$SQL where rownum = 1
    order by FIRST_LOAD_TIME asc;
    mail_conn := utl_smtp.open_connection(mailhost, 25);
    pMessage := 'Prror Mail SAYS :' || chr(13) || 'LOCAL_TRANSACTION_ID:' ||
    DBMS_TRANSACTION.LOCAL_TRANSACTION_ID || chr(13) || 'FORMAT_CALL_STACK:' ||
    DBMS_UTILITY.FORMAT_CALL_STACK || chr(13) || 'FORMAT_ERROR_BACKTRACE:' ||
    DBMS_UTILITY.FORMAT_ERROR_BACKTRACE || chr(13) || 'FORMAT_ERROR_STACK:' ||
    DBMS_UTILITY.FORMAT_ERROR_STACK || chr(13) || 'GET_CPU_TIME:' ||
    DBMS_UTILITY.GET_CPU_TIME || chr(13) || 'GET_TIME:' || DBMS_UTILITY.GET_TIME || chr(13);
    pMessage :=  l_str || chr(13) || '------------------------------------------------' || chr(13) || pMessage ;
    mesg := 'Date: ' ||
    TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss') || crlf ||
    'From: <'|| pSender ||'>' || crlf ||
    'Subject: '|| pSubject || crlf ||
    'To: '||pRecipient || crlf || '' || crlf || pMessage;
    utl_smtp.helo(mail_conn, mailhost);
    utl_smtp.mail(mail_conn, pSender);
    utl_smtp.rcpt(mail_conn, pRecipient);
    utl_smtp.data(mail_conn, mesg);
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN OTHERS THEN
    NULL;
    END error_mail;
    </code>

    Te reason i do it this way is to have a generic exception handler. It is important to get the variables. I need the culprit ID. The DB consists of 17 000 000 animal records and even more settings for each animal. We get about 100 - 200 single row sub-query errors each day, because the data gets messed up by the secretaries. I need to get the animal ID with the error report that way i can fix the error in seconds instead of running multiple Queries to find the issue. The other problem is the DB is very Busy running large debug queries is not really possible. The solution thus far gives me some answers but I got 100 emails yesterday and they were all the same. How do i get everything from the current session.
    CURRENT CODE:
    PROCEDURE error_mail IS
    pMessage   VARCHAR2(2000);
    pSender      VARCHAR2(80) := '[email protected]';
    pRecipient VARCHAR2(80) := '[email protected]';
    pSubject   VARCHAR2(80) := 'Error Package : LGX_P_ANIM';
    mailhost  CONSTANT VARCHAR2(30) := 'mail.home.co.za';
    crlf      CONSTANT VARCHAR2(2):= CHR(13) || CHR(10);
    mesg      VARCHAR2(2000);
    mail_conn utl_smtp.connection;
    l_str VARCHAR2(1000);
    l_id VARCHAR2(100);
    BEGIN
       --select username|| '-' ||sql_text into l_str from v$session, v$sql where audsid = l_Sid and v$session.sql_address = v$sql.address;
       select substr(sql_text,1,999),sql_id into l_str,l_id from v$sql where address = (SELECT prev_sql_addr FROM v$session WHERE audsid = userenv('SESSIONID')) and rownum = 1;
       l_id := l_id || '-' || logix.transpose('select name || ''-'' || value_string from v$sql_bind_capture where sql_id = ''' || l_id || '''',';');
       mail_conn := utl_smtp.open_connection(mailhost, 25);
       pMessage := 'Prror Mail SAYS :' || chr(13) ||
       'LOCAL_TRANSACTION_ID:' || l_id  || chr(13) ||
       'SESSIONID:' || userenv('SESSIONID')  || chr(13) ||
       'FORMAT_CALL_STACK:' || DBMS_UTILITY.FORMAT_CALL_STACK  || chr(13) ||
       'FORMAT_ERROR_BACKTRACE:' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE   || chr(13) ||
       'FORMAT_ERROR_STACK:' || DBMS_UTILITY.FORMAT_ERROR_STACK      || chr(13) ||
       'GET_CPU_TIME:' || DBMS_UTILITY.GET_CPU_TIME      || chr(13) ||
       'GET_TIME:' || DBMS_UTILITY.GET_TIME || chr(13);
       pMessage :=  l_str || chr(13) || '--------------------------------------------------' || chr(13) || pMessage ;
       mesg := 'Date: ' ||
            TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss') || crlf ||
               'From: <'|| pSender ||'>' || crlf ||
               'Subject: '|| pSubject || crlf ||
               'To: '||pRecipient || crlf || '' || crlf || pMessage;
       utl_smtp.helo(mail_conn, mailhost);
       utl_smtp.mail(mail_conn, pSender);
       utl_smtp.rcpt(mail_conn, pRecipient);
       utl_smtp.data(mail_conn, mesg);
       utl_smtp.quit(mail_conn);
    EXCEPTION
      WHEN OTHERS THEN
        NULL;
    END error_mail;
    CURRENT OUTPUT
    SELECT PAR_ID FROM IRISDATA30.PERIOD P WHERE ANI_ID = :B2 AND RELATION_TYPE = 'O' AND NVL(PERIOD_END_DTM,:B1 ) = (SELECT MAX(NVL(PERIOD_END_DTM,:B1 )) FROM IRISDATA30.PERIOD WHERE TO_CHAR(PERIOD_BEGIN_DTM,'DD-MON-YYYY') <= :B1 AND RELATION_TYPE = 'O' AND ANI_ID = P.ANI_ID)
    Prror Mail SAYS :
    LOCAL_TRANSACTION_ID:1jy7g0zrzqmpm-':B2-548721521';':B1-08/23/11 10:40:14';':B1-';':B1-08/23/11 10:40:14'
    SESSIONID:18089990
    FORMAT_CALL_STACK:----- PL/SQL Call Stack -----
      object      line  object
      handle    number  name
    c000000232174828        24  package body INTERGIS.LGX_P_ANIM
    c000000232174828       264  package body INTERGIS.LGX_P_ANIM
    c000000232174828       377  package body INTERGIS.LGX_P_ANIM
    c000000232174828       186  package body INTERGIS.LGX_P_ANIM
    c00000022661c510         1  anonymous block
    FORMAT_ERROR_BACKTRACE:ORA-06512: at "INTERGIS.LGX_P_ANIM", line 246
    FORMAT_ERROR_STACK:ORA-01422: exact fetch returns more than requested number of rows
    GET_CPU_TIME:35754
    GET_TIME:22400142Edited by: user12991926 on Aug 24, 2011 9:03 AM
    Edited by: user12991926 on Aug 24, 2011 9:04 AM

  • Generic error/exception handler

    Well guys, I think I got a challenge for you: I have been thinking for some time about the idea of having a generic error handler for my applications. It's one of these things you should just have: In large GUI apps you usually try to catch all exceptions and display some sort of nice error dialog telling the user what went wrong and what he has to do now. However, there are runtime errors that one can't foresee. These might be bugs, sure, but they happen, so there should be a way of dealing with them. For example, let's say there is a NullPointerException. The clean way would be to display a message box saying something like "Bug!" and giving the user the chance to save his work (or do that automatically). However, this does not seem to be possible. Sure, I could surround every method code with a try { ... }catch(Exception e) and display the dialog, but that seems rather tedious. Does anyone know a better way? Like a common error handling method that is always called when there is an uncaught exception. I dunno, but my IDE JBuilder has something like that, because it is able to stop at "all uncaught exceptions". Any suggestions?
    Thanks guys, or do we have to file a RFE???
    Filip Rindler

    Well, that doesn't work for GUI apps as their main method is done after initializing and all other work is done by the event dispatch thread that is responsible for receiving OS messages (such as mouse motion / clicked / ...). Then this thread calls the event listener methods of registered listeners. It's actually a little more complex how AWT/Swing handles things, but that's the general concept and it is the core of the problem as well: I cannot change any of the event dispatch code (it's deep down in the AWT), so therefore I cannot catch any exceptions there. But maybe there's a hook...

  • Exception Handling Problem In BPM

    All
    I am facing an exception handling problem I am using BPM and , I have caught exception in the transformation step but when there is any data problem in that mapping(mentioned in the transformation)
    it is not throwing the exception . is there any option to collect these type of system exception in  the bpm and give a alert thru mail
    is there any way to collect these type of exception happened in the BPE and raise alert thru generic alert
    Thanks
    Jayaraman

    Hi Jayaraman,
        When you say there is any data problem, does that fail the message mapping that you have defined?
    If the message mapping used in the tranformation fails, it should raise an exception in the BPM.
    Did you test the message mapping using the payload and see if it really fails or not?
    Regards,
    Ravi Kanth Talagana

  • Exception Handling In BPEL  By using Catch Blocks or Fault Policies Or Both

    I have a confusion regarding
    Exception handling :
    When Should i go for 1)Catch Block (Remote , or binding ) in bpel for exception handling .
    2)Fault Policy , Fault binding.xml
    Currently iam using catch blocks , but even fault policy is good , but can i use both...
    Currently in My bpel ,when any error occurs i have to send a error notification by Email .
    Currently i have exposed the email service which shuts emails and write a file with errored Message.
    Hence if any error i will catch i in a parent BPEL, i will just invoke the above email, service .
    So anybody can help me by giving the suggestion how to go for the best approach
    Edited by: anantwag on Mar 23, 2011 6:31 AM

    Currently in My bpel ,when any error occurs i have to send a error notification by Email .
    Currently i have exposed the email service which shuts emails and write a file with errored Message.Seeing your use case I will suggest you to use fault handling framework (fault policy). Fault handling framework should be used where you need generic error handling framework which handles all the faults occured in any composite component. Generally BPEL catch block should be used to propagate error info/fault back to the client/to fault handling framework or to consume an error
    Regards,
    Anuj

  • Exception Handling in UDF?

    Hi experts,
    iam working Scenario file-xi-rfc scenario were in mapping, iam writing an UDF i want to know How to handle the exceptions in UDF and How the user will know where the exception has occurred.
    please send related links.
    note:useful answer will be rewarded.
    regards,
    kumar

    Hi
    XI/PI: Throwing Generic Exceptions from any type of Mapping
    /people/michal.krawczyk2/blog/2007/04/26/xipi-throwing-generic-exceptions-from-any-type-of-mapping
    Throwing Smart Exceptions in XI Graphical Mapping
    /people/alessandro.guarneri/blog/2006/01/26/throwing-smart-exceptions-in-xi-graphical-mapping
    "Fast return" with Java exceptions
    /people/valery.silaev/blog/2007/05/15/fast-return-with-java-exceptions
    Errors, Exceptions, and Asynchronous Web Services
    /people/udi.dahan/blog/2007/03/27/errors-exceptions-and-asynchronous-web-services
    Thanks

  • Exception handling in App. package PeopleCode

    Hi,
    I am accessing a table that is on remote database using DBLink for an update/insert operation using SQLExec. I am trying to implement exception handling to account for the scenario where the remote database is offline so that transaction can continue. However when I use the try-catch block in the app. package PeopleCode somehow the processing does not seem to move forward from the error. The App. pacakage code is triggered by the handler of the service operation. The goal is to simply skip the SQLExec if the table is not available. I am not sure if there is any limitation to the fatal SQL errors which the try-catch can handle.
    As expected i get below error when running select on a view which has remote table in the SQL developer as remote database is down.
    ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
    Has anyone enconutered similar issue with exception handling and best way to move forward in this scenario.
    Any response is much appreciated.
    Thanks,
    Gireesh

    I did this with PL/SQL once. Basically, you want to know if the remote database is available before you execute SQL against it. Here is my function. You can then SQLExec something like select 'x' from dual where my_package.link_available('the_link_name') = 1. If you get a result, then the db link is active. If you don't, it is not active.
    FUNCTION LINK_AVAILABLE(pv_name VARCHAR2)
      RETURN NUMBER AS
            lv_result PLS_INTEGER;
            lv_name   VARCHAR2(128);
        BEGIN
            lv_name := UPPER(pv_name);
            -- parameter check to avoid SQL injection with dynamic SQL below
            -- if the following selects no rows, it will fall through to exception
            -- and return 0;
            SELECT 1
              INTO lv_result
              FROM ALL_DB_LINKS
             WHERE DB_LINK = lv_name;
            -- if we made it this far, then the parameter was a valid db link name
            -- execute SQL to test
            EXECUTE IMMEDIATE 'SELECT 1 FROM PS_INSTALLATION@' || lv_name INTO lv_result;
            RETURN lv_result;
        EXCEPTION
            WHEN OTHERS THEN
                RETURN 0;
      END LINK_AVAILABLE;

  • Exception handling in ODI - common exception handling framework

    Hi,
    I need to come up with a common exception handling framework in an environment where ESB and ODI are being used for interfacing and ELT operations. I am of the opinion that
    1. I am not able to find any documentation wrt exception handling when ODI is used? Can some one help me with some pointers?
    2, When I come up with a common exception handling framework using BPEL, will I be able to invoke the same from ODI.
    Thanks,
    Mahesh

    Thanks for the reply Allan. I haven't used BusinessWorks.
    I did go through this thread before and here's my understanding.
    1. ESB provides the ability of error handling (client management API) but not the exception handling i.e. I can't redirect the flow in case there is an exception in my primary flow. Am I right with my understanding?
    2. Error handling ability of ESB is limited to retryable exceptions viz-a-viz asynchrounous ESB processes (e.g. database listener not up) where in the process can be retried. Am I right here?
    Thanks,
    Mahesh

  • Exception Handling in ADF

    Jdeveloper version 11.1.1.5.0
    Use Case :
    My application has :- 1 Jspx page ( testPage.jspx ) , 1 taskflow ( testExceptionFlow.xml ) , 1 pageFragment ( testOperation.jsff ).
    I have employee table dragged as table on testOperation.jsff with 4 buttons :
    1. Delete - Executes the VO's Delete action.
    2. Commit - AM's commit operation ( through datacontrol )
    3. CustomDeleteAndCommit - One method in VOImpl which deletes the currentRow and calls this.getDBTransaction().commit() method.
    4. CustomCommitThroughBean - Action listener in beans calls the commit through operation binding.
    I have secured my application and create two users in jazn.xml User1 and User2. Now both users are logged in to the application using different browser.
    Both users can see employee with empId 100.
    User1 selects a employee with empId 100 and clicks Delete button. Further clicks Commit button.
    User2 selects the same employee with empId 100 and clicks Delete button. Further he can choose to commit through different options :
    a) Commit
    b) CustomCommitThroughBean
    OR
    CustomDeleteAndCommit
    Obviously there will be jboException stating that row is already delete. When I am calling it through CustomCommitThroughBean operationBinding.getErrors() has errors, so I don't see error on UI.
    I see a couple of posts about different ways of handling Exception :
    [Using Exception Handler in an ADF Task Flow | https://blogs.oracle.com/ADFProgrammers/entry/using_exception_handler_in_an]
    [Extending the ADF Controller exception handler | https://blogs.oracle.com/jdevotnharvest/entry/extending_the_adf_controller_exception_handler]
    [Task Flow Exception Handler | http://adfpractice-fedor.blogspot.com/2011/12/task-flow-exception-handler-you-must.html]
    [Exception Handling in adf (Part 1) | http://adfwithejb.blogspot.com/2012/05/exception-handling-in-adf-part-1.html ]
    Which method of exception handling is applicable should be chosen ?
    I just want to notify user about exception through some custom message and table should get refreshed for further operation.
    My observations :
    I get an error dialog in case :
    Commit & CustomDeleteAndCommit
    whereas no default error in case : CustomCommitThroughBean
    I have uploaded my application [here | http://dl.dropbox.com/u/70986236/BlogApplication/OperationBindingExecuteErrorApp.zip ] . Want to implement exception handling in this application.
    Thanks,
    Rajdeep
    Edited by: Rajdeep on Jul 26, 2012 9:45 PM

    When you invoke an operation programmatically through an ADF OperationBinding, the eventual exception is not thrown to you but it is reported to the BindingContainer and the BindingContainer automatically adds a FacesMessage of ERROR severity to the FacesContext. If you have an <af:messages> tag in your ADF Faces page, this error message should be displayed automatically.
    Dimitar

  • Exception Handling in BPEL

    Guys,
    I have exposed the following class as Web-Service, using Axis.
    public class ExceptionCreator {
    public ExceptionCreator(){
    public ReturnObject generate(boolean flag) throws CustomException{
    if(flag){
    throw new CustomException("This is a custom exception");
    }else{
    return new ReturnObject(1,"NO EXCEPTION");
    where ReturnObject is a simple JavaClass with two member variables id & name and CustomException is a class extended from Exception superclass in Java.
    Using axis, writing appropriate serializers in wsdd, I created a web-service out of this and imported the WSDL from Axis as a Partner Link in BPEL.
    If I pass true as Input and if I specify "{http://schemas.oracle.com/bpel/extension}remoteFault as faultName in the catch, the exception does get caught. However, I am unable to access the details of the same which looks like below:
    [2005/09/26 18:44:11] "{http://schemas.oracle.com/bpel/extension}remoteFault" has been thrown.
    <remoteFault xmlns="http://schemas.oracle.com/bpel/extension">
    <part name="code">
    <code>Server.userException</code>
    </part>
    <part name="summary">
    <summary>when invoking endpointAddress 'http://kingfisher:9080/axis/services/ExceptionCreatorSewrvice', com.misys.equationcore.tutorials.CustomException: This is a custom exception</summary>
    </part>
    <part name="detail">
    <detail>AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException faultSubcode: faultString: com.misys.equationcore.tutorials.CustomException: This is a custom exception faultActor: faultNode: faultDetail: {http://kingfisher:9080/axis/services/ExceptionCreatorSewrvice}fault:<exceptionMessage type="soapenc:string">String CustomException Constructor</exceptionMessage> {http://xml.apache.org/axis/}hostname:kingfisher</detail>
    </part>
    </remoteFault>
    I am trying to access the contents of this fault in a Assign activity where I want to display the actual java exception as output.
    Any clues as to how I can access the same?
    Thanks in advance,
    ~Soumen.

    Currently in My bpel ,when any error occurs i have to send a error notification by Email .
    Currently i have exposed the email service which shuts emails and write a file with errored Message.Seeing your use case I will suggest you to use fault handling framework (fault policy). Fault handling framework should be used where you need generic error handling framework which handles all the faults occured in any composite component. Generally BPEL catch block should be used to propagate error info/fault back to the client/to fault handling framework or to consume an error
    Regards,
    Anuj

  • UTL file exception handling oracle 11g

    We use oracle 11g
    We use UTL file and exception handling in many place. Thanks in advance.
    We have many utl program and we are writing same exception handling code ,copy and paste .
    It is possible to create new UTL exception procedure and call it.
    I am not sure how to write generic UTL exception procedure and reuse the same.
    I am learning oracle etl files method.
    Please advise.
    sample program 1 :
    DECLARE
    fileHandler UTL_FILE.FILE_TYPE;
    BEGIN
    fileHandler := UTL_FILE.FOPEN('test_dir', 'test_file.txt', 'W');
    UTL_FILE.PUTF(fileHandler, 'Writing TO a file\n');
    UTL_FILE.FCLOSE(fileHandler);
    EXCEPTION
    when utl_file.invalid_path then
    raise_application_error(-20001,
    'INVALID_PATH: File location or filename was invalid.');
    when utl_file.invalid_mode then
    raise_application_error(-20002,
    'INVALID_MODE: The open_mode parameter in FOPEN was invalid.');
    when utl_file.invalid_filehandle then
    raise_application_error(-20002,
    'INVALID_FILEHANDLE: The file handle was invalid.');
    when utl_file.invalid_operation then
    raise_application_error(-20003,
    'INVALID_OPERATION: The file could not be opened or operated on as requested.');
    when utl_file.read_error then
    raise_application_error(-20004,
    'READ_ERROR: An operating system error occurred during the read operation.');
    when utl_file.write_error then
    raise_application_error(-20005,
    'WRITE_ERROR: An operating system error occurred during the write operation.');
    when utl_file.internal_error then
    raise_application_error(-20006,
    'INTERNAL_ERROR: An unspecified error in PL/SQL.');
    when utl_file.invalid_filename then
    raise_application_error(-20010, 'The filename parameter is invalid.');
    WHEN OTHERS THEN
    IF UTL_FILE.IS_OPEN(fileHandler ) THEN
    UTL_FILE.FCLOSE (fileHandler );
    END IF;
    RAISE;
    END;
    How to write generic procedure of utl exception handling ?
    please advise.
    create or replace procedure sp_utl_exception
    begin
    when utl_file.invalid_path then
    raise_application_error(-20001,
    'INVALID_PATH: File location or filename was invalid.');
    when utl_file.invalid_mode then
    raise_application_error(-20002,
    'INVALID_MODE: The open_mode parameter in FOPEN was invalid.');
    when utl_file.invalid_filehandle then
    raise_application_error(-20002,
    'INVALID_FILEHANDLE: The file handle was invalid.');
    when utl_file.invalid_operation then
    raise_application_error(-20003,
    'INVALID_OPERATION: The file could not be opened or operated on as requested.');
    when utl_file.read_error then
    raise_application_error(-20004,
    'READ_ERROR: An operating system error occurred during the read operation.');
    when utl_file.write_error then
    raise_application_error(-20005,
    'WRITE_ERROR: An operating system error occurred during the write operation.');
    when utl_file.internal_error then
    raise_application_error(-20006,
    'INTERNAL_ERROR: An unspecified error in PL/SQL.');
    when utl_file.invalid_filename then
    raise_application_error(-20010, 'The filename parameter is invalid.');
    WHEN OTHERS THEN
    IF UTL_FILE.IS_OPEN(fileHandler ) THEN
    UTL_FILE.FCLOSE (fileHandler );
    END IF;
    RAISE;
    end;

    Mahesh Kaila wrote:
    Hello,
    Common procedure to log exception in log file
    create or replace procedure sp_utl_exception (log_dir varchar2, log_file varchar2, exception_msg varchar2)
    is
    hnd_file   UTL_FILE.file_type;
    begin
    hnd_file := UTL_FILE.fopen (log_dir, log_file, 'A');
    UTL_FILE.put_line (hnd_file, exception_msg);
    UTL_FILE.fclose (hnd_file);
    exception
    when others
    then
    raise;
    end;
    Very poor implementation.
    a) Absolutely no need for that exception handler in there. It should be removed.
    b) As it's a procedure for logging exceptions relating to UTL_FILE, it would seem error prone to be logging the errors with UTL_FILE. For example, what is it supposed to do if the exception is raised because of lack of disk space in those file locations? How is it going to write out the exception with the disk full? Also, if the exception handler is used by multiple processes, then only 1 process at a time can access the log file to write it's exceptions, so it doesn't scale well. Better logging is done by having an autonomous transaction procedure that writes log/trace messages to dedicated table(s). That also means that the logs etc. can be viewed, as appropriate, from any client using SQL (either manually or through a application written to view logs etc.), rather than requiring physical/remote access to the server o/s to go and view the contents of the file, which in itself could lock the file and prevent any process from writing further logs whilst it's being used.

  • Integration Process - Exception Handling

    Hi,
    I have developed an integration process, which call web-service, and catch it's exception. The problem is that the WS returns generic exception (SYSTEM) for all exceptions, but with different text for each one.
    Is there any way to get the exception text (the text itself and not the type), analyze it and handle the process correspondingly?

    Hi Shai,
    When you are calling the web-service method in BPM, put it in a block.....in the exception branch of the block, the control will go when the web-service will give exception.........so then put a switch in the exception branch - put the exception message as a condition for switching - do switching on basis of message text - and in the switch branches, do what you want to do for those exceptions.
    Hope it solves your query.
    Thanks,
    Rajeev Gupta

Maybe you are looking for

  • FCExp to PCP5 - Render Files Offline?

    I can't export a movie file that I converted from FC Express to FC Pro 5 because it keeps telling me that render files are missing...but apparently it's not the clips at fault but the transitions. Yet, try as I may to render, it will not render. Any

  • Can I use a pictures file name as a title?

    I have several master pages with 2 up, 6 up 9 up image boxes with a text box directly underneath. The file name of the pics are also the title of the picture. Can I drag a pic into the box and have the name of that file come up in the text box? Prefe

  • Photoshop is very slow in lion.

    This is the only problem -so far- that I face with Lion. All other apps are working fine and I like some of the features of Lion. BUT: Photoshop is very slow. I tried disabling font preview. It helped a little but the overall experience of Photoshop

  • How to restore reading list in safari - lion

    I accidentally pushed erase on my reading list in Safari.  I restored my computer via time machine but the ready list didn't come through.  How can I restore my reading list from time machine?

  • Java apis for sending SMS

    I want to send sms through a mobile connected to my computer through some datacable. Are there any APIs or tools or anyhting in JAVA to do this? I will be happy if its available for Linux as well as windows