Never implemented exception handling  in Stored Procedures

I have lots of stand alone stored procedures callled from .NET 20 programs that follow the following pattern. They runn against Oracle 10.2 on Win2003. The only deviiation is a couple where I insert to temptables. I specify a parameter for messages but don't know the best way to implement for Oracle as well as any tips on ODP.NET/oracle interactions error handling.
1. Is it recommended to implement exception handling in With Clauses?
2. If there is an exception in one cursor's SQL, how do I still execute the second?
3. Is it best in some circumstances to pass a null back to client and check for null in program?
From .NET programs I have run into a couple of problems.
4. TNS packet failure.
Anyways any suggestions or experiences are welcome.
CREATE OR REPLACE  PROCEDURE   GET_SALES_DATA
                  ,   p_businessdate      in   date                 
                  ,   p_message         out varchar2     
                  ,   p_rcSales             out sys_refcursor
                  ,   p_rInventory            out sys_refcursor
) is
open p_rcSales for
with somedata as (select ...)
, someMoreData as (selct ...)
-- Main select
Select * from somedata sd inner join somemoredata  smd on smd.key   = sd.key;
open p_rcInventory for
with somedata as (select ...)
, someMoreData as (selct ...)
-- Main select
Select * from somedata sd inner join somemoredata  smd on smd.key   = sd.key;
-- CODE NOT IMPLEMENTED
-- exception 
-- when TOO_MANY_ROWS  then  select 'Error handling for future implementations' into p_message from dual ;
-- when NO_DATA_FOUND  then  select 'Error handling for future implementations. No data'  into p_message from dual;
-- when others         then  raise_application_error(-20011,'Unknown Exception in GET_SALES_DATA Function');
-- WHEN invalid_business_date then  select 'Invalid: Business date is in the current work week.' into p_message from dual ;
END GET_SALES_DATA;Pseudocode'ish because Module level variables and properties have not been defined here for brevity.
Public Class WebPage1
PAge_Load
   GetData
End Class Data Access Layer
Public Class DAL
Public Sub GetOracleData()
            Dim conn As OracleConnection
                Try
                    conn = New OracleConnection
                Catch ex As Exception
                    Throw ex
                End Try
                Dim cmd As New OracleCommand
                With cmd
                    conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ToString
                    cmd.CommandText = DATABASE.GetSalesData
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Connection = conn
                End With
                cmd.Connection = conn
                Dim oparam As OracleParameter
                oparam = cmd.Parameters.Add("p_businessdate", OracleDbType.Date)
                oparam.Value = BusinessDate.ToString("dd-MMM-yy")
                oparam = cmd.Parameters.Add("p_message", OracleDbType.Varchar2, ParameterDirection.Output)
                oparam = cmd.Parameters.Add("p_rc_inven_csv", OracleDbType.RefCursor, ParameterDirection.Output)
                oparam = cmd.Parameters.Add("p_rcSales", OracleDbType.RefCursor, ParameterDirection.Output)
                oparam = cmd.Parameters.Add("p_rcInventory", OracleDbType.RefCursor, ParameterDirection.Output)
                Dim Adapter As New OracleDataAdapter(cmd)
                Try
                    Adapter.TableMappings.Add("Table", Sales)
                    Adapter.TableMappings.Add("Table1", Inventory)              
                    Adapter.Fill(dsOracleData)
                Catch ex As OracleException
                    HandleError("Exception Retrieving Oracle Data", ex, MethodInfo.GetCurrentMethod.Name, True)
                 Finally
                    If conn.State = ConnectionState.Open Then
                        conn.Close()
                    End If
                End Try
                dbMessages = cmd.Parameters("p_message").ToString
            End If
            arrStatusMessages.Add("Retrieved Oracle Data Successfully")
        End Sub
       ' Original Implementation ; No longer used
        Public function GetOracleData
           Dim conn As New OracleConnection
            conn.ConnectionString = dbconn.Connectionstring
             Dim cmd As New OracleCommand
                With cmd
                    conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ToString
                    cmd.CommandText = DATABASE.GetSalesData
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Connection = conn
                End With
                cmd.Connection = conn
                Dim oparam As OracleParameter
                oparam = cmd.Parameters.Add("p_businessdate", OracleDbType.Date)
                oparam.Value = BusinessDate.ToString("dd-MMM-yy")
                oparam = cmd.Parameters.Add("p_message", OracleDbType.Varchar2, ParameterDirection.Output)
                             oparam = cmd.Parameters.Add("p_rcSales", OracleDbType.RefCursor, ParameterDirection.Output)
                oparam = cmd.Parameters.Add("p_rcInventory", OracleDbType.RefCursor, ParameterDirection.Output)
                Dim Adapter As New OracleDataAdapter(cmd)
                Try
                    Adapter.TableMappings.Add("Table", Sales)
                    Adapter.TableMappings.Add("Table1", Inventory)              
                    Adapter.Fill(dsOracleData)
                dim dt as datatable = dsoracledata.tables("sales")
                If IsDataNull(dt) Then
                     _errorType = DBErrorType.NullData
                End If
                If isDataEmpty(dt) Then
                     _errorType = DBErrorType.EmptyData
                End If
                _hasError = False
            Catch oraEx As OracleException
                  _ExceptionText = oraEx.Message.ToString
                _errorType = DBErrorType.OracleException
#If DEBUG Then
                Throw oraEx
#End If
            Catch zeroEx As DivideByZeroException
                _ExceptionText = zeroEx.Message.ToString
                _errorType = DBErrorType.DivideByZeroException
#If DEBUG Then
                Throw zeroEx
#End If
            Catch oflowEx As OverflowException
                _ExceptionText = oflowEx.Message.ToString
                _errorType = DBErrorType.OverflowException
#If DEBUG Then
                Throw oflowEx
#End If
            Catch argEx As InsufficientMemoryException
                _ExceptionText = argEx.Message.ToString
                _errorType = DBErrorType.InsufficientMemoryException
#If DEBUG Then
                Throw argEx
#End If
            Catch nomemEx As OutOfMemoryException
                _ExceptionText = nomemEx.Message.ToString
                _errorType = DBErrorType.OutOfMemoryException
#If DEBUG Then
                Throw nomemEx
#End If
            Catch Ex As Exception
                _ExceptionText = Ex.Message.ToString
                _errorType = DBErrorType.GenericException
#If DEBUG Then
                Throw Ex
#End If
            Finally
                If conn.State = ConnectionState.Open Then
                    conn.Close()
                End If
            End Try
End class Error Class
Public Class Errors
       Public Sub ExitClass()
            Return
        End Sub
        ' 'blnWriteNow says when Error is critical and no further processing needs to be done by class, then write to event logs or text files and call exit class
        '  to return control back to webpage. This is my first time trying this way.
        Public Sub HandleError(ByVal friendlyMsg As String, ByVal objEx As Exception, ByVal methodInfo As String, Optional ByVal blnWriteNow As Boolean = False)
            If Not blnWriteNow Then Exit Sub
            Dim strMessages As String
            strMessages = arrStatusMessages
            'Send error email
            If  blnSendEmails Then
                 SendMail("[email protected],  strMessages. applicationname, " has thrown  error. ")
            End If
          'Throw error for   debugging
            If  blnThrowErrors Then  
                        Throw New Exception(strMessages & vbCrLf & objEx.Message)
            End If
           ' Write to event log and if not available (shared hosting environment), write to text log
            If blnWriteNow Then
                If  blnWriteToEvtLog Then
                    If  blnCanWriteToEvtLog Then    'Program has write permission to log
                         WriteToEventLog(strMessages, _appname, EventLogEntryType.Error,  appname)
                    Else
                        If Not Directory.Exists( appPath & "\log") Then
                            Try
                                Directory.CreateDirectory( appPath & "\log")
                            Catch ex As Exception
                                arrStatusMessages.Add("Cant't write to event log or create a directory")
                            End Try
                        End If
                    End If
                End If
            End If          
        End Sub
End Class

I have lots of stand alone stored procedures callled from .NET 20 programs that follow the following pattern. They runn against Oracle 10.2 on Win2003. The only deviiation is a couple where I insert to temptables. I specify a parameter for messages but don't know the best way to implement for Oracle as well as any tips on ODP.NET/oracle interactions error handling.
1. Is it recommended to implement exception handling in With Clauses?
2. If there is an exception in one cursor's SQL, how do I still execute the second?
3. Is it best in some circumstances to pass a null back to client and check for null in program?
From .NET programs I have run into a couple of problems.
4. TNS packet failure.
Anyways any suggestions or experiences are welcome.
CREATE OR REPLACE  PROCEDURE   GET_SALES_DATA
                  ,   p_businessdate      in   date                 
                  ,   p_message         out varchar2     
                  ,   p_rcSales             out sys_refcursor
                  ,   p_rInventory            out sys_refcursor
) is
open p_rcSales for
with somedata as (select ...)
, someMoreData as (selct ...)
-- Main select
Select * from somedata sd inner join somemoredata  smd on smd.key   = sd.key;
open p_rcInventory for
with somedata as (select ...)
, someMoreData as (selct ...)
-- Main select
Select * from somedata sd inner join somemoredata  smd on smd.key   = sd.key;
-- CODE NOT IMPLEMENTED
-- exception 
-- when TOO_MANY_ROWS  then  select 'Error handling for future implementations' into p_message from dual ;
-- when NO_DATA_FOUND  then  select 'Error handling for future implementations. No data'  into p_message from dual;
-- when others         then  raise_application_error(-20011,'Unknown Exception in GET_SALES_DATA Function');
-- WHEN invalid_business_date then  select 'Invalid: Business date is in the current work week.' into p_message from dual ;
END GET_SALES_DATA;Pseudocode'ish because Module level variables and properties have not been defined here for brevity.
Public Class WebPage1
PAge_Load
   GetData
End Class Data Access Layer
Public Class DAL
Public Sub GetOracleData()
            Dim conn As OracleConnection
                Try
                    conn = New OracleConnection
                Catch ex As Exception
                    Throw ex
                End Try
                Dim cmd As New OracleCommand
                With cmd
                    conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ToString
                    cmd.CommandText = DATABASE.GetSalesData
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Connection = conn
                End With
                cmd.Connection = conn
                Dim oparam As OracleParameter
                oparam = cmd.Parameters.Add("p_businessdate", OracleDbType.Date)
                oparam.Value = BusinessDate.ToString("dd-MMM-yy")
                oparam = cmd.Parameters.Add("p_message", OracleDbType.Varchar2, ParameterDirection.Output)
                oparam = cmd.Parameters.Add("p_rc_inven_csv", OracleDbType.RefCursor, ParameterDirection.Output)
                oparam = cmd.Parameters.Add("p_rcSales", OracleDbType.RefCursor, ParameterDirection.Output)
                oparam = cmd.Parameters.Add("p_rcInventory", OracleDbType.RefCursor, ParameterDirection.Output)
                Dim Adapter As New OracleDataAdapter(cmd)
                Try
                    Adapter.TableMappings.Add("Table", Sales)
                    Adapter.TableMappings.Add("Table1", Inventory)              
                    Adapter.Fill(dsOracleData)
                Catch ex As OracleException
                    HandleError("Exception Retrieving Oracle Data", ex, MethodInfo.GetCurrentMethod.Name, True)
                 Finally
                    If conn.State = ConnectionState.Open Then
                        conn.Close()
                    End If
                End Try
                dbMessages = cmd.Parameters("p_message").ToString
            End If
            arrStatusMessages.Add("Retrieved Oracle Data Successfully")
        End Sub
       ' Original Implementation ; No longer used
        Public function GetOracleData
           Dim conn As New OracleConnection
            conn.ConnectionString = dbconn.Connectionstring
             Dim cmd As New OracleCommand
                With cmd
                    conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ToString
                    cmd.CommandText = DATABASE.GetSalesData
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Connection = conn
                End With
                cmd.Connection = conn
                Dim oparam As OracleParameter
                oparam = cmd.Parameters.Add("p_businessdate", OracleDbType.Date)
                oparam.Value = BusinessDate.ToString("dd-MMM-yy")
                oparam = cmd.Parameters.Add("p_message", OracleDbType.Varchar2, ParameterDirection.Output)
                             oparam = cmd.Parameters.Add("p_rcSales", OracleDbType.RefCursor, ParameterDirection.Output)
                oparam = cmd.Parameters.Add("p_rcInventory", OracleDbType.RefCursor, ParameterDirection.Output)
                Dim Adapter As New OracleDataAdapter(cmd)
                Try
                    Adapter.TableMappings.Add("Table", Sales)
                    Adapter.TableMappings.Add("Table1", Inventory)              
                    Adapter.Fill(dsOracleData)
                dim dt as datatable = dsoracledata.tables("sales")
                If IsDataNull(dt) Then
                     _errorType = DBErrorType.NullData
                End If
                If isDataEmpty(dt) Then
                     _errorType = DBErrorType.EmptyData
                End If
                _hasError = False
            Catch oraEx As OracleException
                  _ExceptionText = oraEx.Message.ToString
                _errorType = DBErrorType.OracleException
#If DEBUG Then
                Throw oraEx
#End If
            Catch zeroEx As DivideByZeroException
                _ExceptionText = zeroEx.Message.ToString
                _errorType = DBErrorType.DivideByZeroException
#If DEBUG Then
                Throw zeroEx
#End If
            Catch oflowEx As OverflowException
                _ExceptionText = oflowEx.Message.ToString
                _errorType = DBErrorType.OverflowException
#If DEBUG Then
                Throw oflowEx
#End If
            Catch argEx As InsufficientMemoryException
                _ExceptionText = argEx.Message.ToString
                _errorType = DBErrorType.InsufficientMemoryException
#If DEBUG Then
                Throw argEx
#End If
            Catch nomemEx As OutOfMemoryException
                _ExceptionText = nomemEx.Message.ToString
                _errorType = DBErrorType.OutOfMemoryException
#If DEBUG Then
                Throw nomemEx
#End If
            Catch Ex As Exception
                _ExceptionText = Ex.Message.ToString
                _errorType = DBErrorType.GenericException
#If DEBUG Then
                Throw Ex
#End If
            Finally
                If conn.State = ConnectionState.Open Then
                    conn.Close()
                End If
            End Try
End class Error Class
Public Class Errors
       Public Sub ExitClass()
            Return
        End Sub
        ' 'blnWriteNow says when Error is critical and no further processing needs to be done by class, then write to event logs or text files and call exit class
        '  to return control back to webpage. This is my first time trying this way.
        Public Sub HandleError(ByVal friendlyMsg As String, ByVal objEx As Exception, ByVal methodInfo As String, Optional ByVal blnWriteNow As Boolean = False)
            If Not blnWriteNow Then Exit Sub
            Dim strMessages As String
            strMessages = arrStatusMessages
            'Send error email
            If  blnSendEmails Then
                 SendMail("[email protected],  strMessages. applicationname, " has thrown  error. ")
            End If
          'Throw error for   debugging
            If  blnThrowErrors Then  
                        Throw New Exception(strMessages & vbCrLf & objEx.Message)
            End If
           ' Write to event log and if not available (shared hosting environment), write to text log
            If blnWriteNow Then
                If  blnWriteToEvtLog Then
                    If  blnCanWriteToEvtLog Then    'Program has write permission to log
                         WriteToEventLog(strMessages, _appname, EventLogEntryType.Error,  appname)
                    Else
                        If Not Directory.Exists( appPath & "\log") Then
                            Try
                                Directory.CreateDirectory( appPath & "\log")
                            Catch ex As Exception
                                arrStatusMessages.Add("Cant't write to event log or create a directory")
                            End Try
                        End If
                    End If
                End If
            End If          
        End Sub
End Class

Similar Messages

  • Best Practice for Implementing Exception Handling in BPEL

    Hi All,
    what is the best practice and the approach to follow Exception Handling in BPEL.
    1) Do we need to implement Exception Handling in BPEL as we do in Java, means
         method 3 throws error to method 2 (if any) and
         method 2 throws error to method 1 (if any) and
         finally method 1 throws error to the main Class.
    If we replicate the above scenario to BPEL
    In BPEL main Scope have Custom Fault, Catch ALL
         Each Invoke is surrounded by a Scope Activity with Remote Fault, Binding Fault & Custom Fault
    and follow the paradigm of Java, assuming we have Inner Scopes
         [ OR ]
    2) In BPEL main Scope have all exceptions defined like
         Remote Fault,
         Binding Fault,
         anyOther System Fault (selectionFailure / forcedTermination),
         Custom Fault (if required) and
         CatchALL
         and also
         each Invoke is surrounded by a Scopes Acitivity with Custom Fault (business fault) exception Handling
    I feel 1st one may not be a good practice, may be i am wrong...
    Any Suggestions from experts.
    Thanks in Advance
    anvv sharma

    Hi-
    In you can create different scope and use catch branch to catch binding, remote, custom faults, business faults etc. If an error happens in a scope it will not move to the next scope( eg: you have 3 scope, error occured in 2nd scope then it will not propogate to the 3rd scope. One thing to be noticed here is your transaction in the 1st scope doesnt gets commited when an error happens in 2d scope).
    You can have a catch all to catch error which are not being caught at catch level. So if any error happens which is not defined in catch block then then it will be caught in catch all branch.
    Edited by: 333333 on Apr 12, 2011 9:39 AM

  • "user defined exception" in a stored procedure and APEX

    I would like to use user defined exception in a stored procedure or trigger in a APEX application.
    Does anybody know how to do it ? or know where can I find a good reference ?
    Thanks,

    raise_application_error(-20001, 'error message');
    Scott

  • Implementing Exception Handling Application Block in custom web parts, event receivers

    hi,
      I am currently implementing try {} catch(Exception expp) { throw expp;} to handle exceptions in my intranet appln.
    I have several custom web parts, event receivers, few console applciations as timer jobs etc. If i want to implement a  robust exception handling what should be  the approach. by searching, i saw, ms patterns n practices provides the
    appln blocks.
    But I think[ pls correct me if i am wrong ] those  appln blocks are meant for asp.net applns ONLY.
    if not, anyone has implemented those appln blocks in SP development? if yes, can anyone provide one sample /  link to implement Exception Handling in SP.
    help is appreciated! 

    Hi,
    Here are some articles for your reference:
    Handling Error Centrally in a SharePoint Application
    http://www.codeproject.com/Articles/26236/Handling-Error-Centrally-in-a-SharePoint-Applicati
    Using Microsoft Enterprise Library Application Block in SharePoint
    http://www.codeproject.com/Articles/21389/Using-Microsoft-Enterprise-Library-Application-Blo
    Exception Handling in SharePoint
    http://spmatt.wordpress.com/2012/02/01/exception-handling-in-sharepoint/
    Best Regards
    Dennis Guo
    TechNet Community Support

  • Exception handling in stored process, loop IF..ELSE

    Hello Guys,
    we want to put in exception handling in the loop but get the following error:
    Error(43,3): PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following: begin case declare end exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe
    create or replace
    PROCEDURE xxxx
    FOR MESSSY IN
    select I.*
    FROM x I
    LOOP
    IF upper(CODE)='N' THEN
    INSERT INTO T_MESS(MP)
    select I.MP_ID
    FROM T_ME
    ELSIF upper(MESSSY.k2)='L' THEN
    DELETE T_MESS WHERE T_MESS.MP = MESSSY.MP;
    END IF;
    EXCEPTION
    WHEN DUP_VAL_ON_INDEX THEN
    A program attempted to insert duplicate values in a column that is constrained by a unique index.
    DBMS_OUTPUT.PUT_LINE ('A program attempted to insert duplicate values in a column that is constrained by a unique index.')
    --No Rollback
    END;
    COMMIT;
    END LOOP;
    END xxxx;
    does someone know why?

    BluShadow wrote:
    Well, your code is missing all sorts of bits and we don't have your data or your exact logic to know what it's supposed to be achieving.
    That is right, you dont have my data and that is why I was suprised by your comment.
    Since the input table might contain a few thousand rows and each of those might need to
    be considered N , D, or C and each case has a different handling I can not imagine how this
    can be all done with a merge statement.
    MERGE
    T_METRICPOINT_META with T_METRICSSYSTEM_LOAD where T_METRICSSYSTEM_LOAD .LOAD_DATE=to_char(sysdate)
    WHEN MATCHED THEN --we know those are the metric points that have to be loaded today, but we still need to do a IF..ELSE to handle them
    WHEN NOT MATCHED THEN -- not considered in todays load
    ----original code-----
    create or replace
    PROCEDURE myprocedure AS
    BEGIN
    --Extracting the records from T_METRICSSYSTEM_LOAD which have todays load date. Corresponding to these MP_System, we extract the MP_IDs from the T_METRICPOINT_META table.
    --Comapring these MP_IDs with the MP_IDs from the source(T_METRICPOINT_IMPORT) and extracting only those Metric points which need to be loaded today.
    FOR METRICSSYSTEM IN
    select I.*
    FROM T_METRICPOINT_IMPORT I
    where I.LOADDATE = TO_CHAR(SYSDATE) AND I.MP_ID IN
    (select a.MP_ID
    from T_METRICPOINT_META a INNER JOIN T_METRICSSYSTEM_LOAD b on a.MP_SYSTEM = b.MP_SYSTEM where b.LOAD_DATE=to_char(sysdate))
    LOOP
    --If mutation code in the source/import data is "N", the record is inserted as it is in the "T_METRICPOINTS" table.
    IF upper(METRICSSYSTEM.MUTATIONCODE)='N' THEN --new
    INSERT INTO T_METRICPOINTS(MP_ID, ......)
    SELECT DISTINCT I.MP_ID,.....
    FROM T_METRICPOINT_IMPORT I WHERE I.MP_ID = METRICSSYSTEM.MP_ID
    ELSIF upper(METRICSSYSTEM.MUTATIONCODE)='D' THEN --delete
    DELETE T_METRICPOINTS WHERE T_METRICPOINTS.MP_ID = METRICSSYSTEM.MP_ID AND T_METRICPOINTS.KEY = METRICSSYSTEM.KEY;
    ELSIF upper(METRICSSYSTEM.MUTATIONCODE)='C' THEN --correction
    UPDATE T_HISTORYMETRICPOINTS H
    SET CHANGE_DATE = to_char(sysdate)
    WHERE H.MP_ID=METRICSSYSTEM.MP_ID AND H.KEY = METRICSSYSTEM.KEY;
    INSERT INTO T_HISTORYMETRICPOINTS(MP_ID, KEY, .....)
    --The distinct here is used, to handle 2 identical records in the input table with correction value "C". This would insert into 1 record in the T_HISTORYMETRICPOINTS table without
    --violating the primary key constraint.
    select DISTINCT I.MP_ID,I.KEY, ....
    FROM T_METRICPOINT_IMPORT I WHERE I.MP_ID = METRICSSYSTEM.MP_ID
    --END IF;
    END IF;
    COMMIT;
    END LOOP;
    END myprocedure;

  • Error Handling in Stored Procedure code

    Hi All,
    I need to know which step is failing and whats the error message when i run a stored procedure.
    Lets say i have a stored procedure with below content.So i want to know which of the below four statements failed,and
    the error message belonging to it.
    How can i modify the below code to achieve my output.
    begin try
    DELETE FROM Table1 WHERE Column1 = 'A'
    UPDATE Table1 SET Column1 = 'C' WHERE Column2 = 'B'
    SELECT * FROM Table1 WHERE Column3 = 'C'
    SELECT * FROM Table1 WHERE Column4 = 'D'
    end try
    begin catch
    end catch
    Thanks in Advance!!

    Take a look at this excellent TechNet Wiki article
    Structured
    Error Handling Mechanism in SQL Server 2012
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Exceptions in a stored procedure

    Hi
    I am writing a stored procedure and I am running a select statement. On NO_DATA_FOUND exception, I want to raise another exception called NO_EMP_FOUND. Question is where in the stored procedure I have to define this. Remember that the select statement is within a BEGIN and END
    begin
    no_emp_found exception;
    Begin
    select a,b INTO d,c
    FROM BLABLA
    WHERE BLA = BLA;
    EXCEPTION
    WHEN NO_DATA_FOUND
    RAISE NO_EMP_FOUND;
    END;
    <<is this where I can define the NO_EMP_FOUND, or it has to be within the internal begin and end??>>
    END;
    Thanks

    Thanks damorgan,
    I understand how exceptions work, but my question is specifially about how exception has to be defined when there are 2 "begins" in the procedure and the exception is caught in the internal begin. to elaborate of What I am tring to say, consider this
    procedure finderror is
    BEGIN
    no_emp_found EXCEPTION;
    begin
    (SOME SELECT STATEMENT)
    WHEN NO_DATA_FOUND THEN
    RAISE no_emp_found
    end;
    EXCEPTION
    WHEN no_emp_found
    dbms.putline ('CAUGHT IT')
    end finderror;
    will the above code work, I mean conceptually (ignore the syntax). Or do I have to define the following part inside the internal (begin...end)
    EXCEPTION
    WHEN no_emp_found
    dbms.putline ('CAUGHT IT')
    Thanks

  • How to implement Exception Handling error in IDoc to File and RFC to File

    Hi,
    We are implementing the two below scenarios :
    1. IDOC to File
    2. RFC to File
    We have to implement the Exception Handling for the above two cases. Kindly could you provide the inputs to implement the Exception Handling for the above two cases.
    Please provide the precious inputs to implement this.
    Thanks,
    Ramesh

    Hi Ramesh,
    The exception handling for idocs
    http://help.sap.com/saphelp_nw04/helpdata/en/dc/6b7f1543d711d1893e0000e8323c4f/frameset.htm
    Exception handling in File to IDoc Scenario
    For RFCs
    Re: Passing SAP Exceptions to a sync SOAP Call
    Error Handling when using RFC
    Exception Handling while Calling RFC - BPM
    handle exceptions in remote function modules
    Regards,
    Prateek

  • Exception handling in calling procedure

    Hi,
    i have a package where currently am making calls to private procedures from public procedure.
    and the senario is:-
    create package body p_tst
    is
    ex_failed exception;
    -- this is private proc
    procedure p_private
    is
    begin
    raise ex_failed;
    exception
    when ex_failed
    then
    raise;
    end p_private;
    procedure p_public
    is
    begin
    -- nomaking call to private
    -- procedure
    p_private;
    -- here i need to catch
    -- the raised exception
    -- passed from the called
    -- procedure
    when ex_failed
    end p_public;
    end;
    basically i want to catch the exception being passed from called procedure to calling procedure, and raise the same exception in calling procdure.
    is it possible to catch the same exception in the calling procedure?

    Yes, you can catch the same exception in the calling procedure, exceptions are propagated to the caller if they are not handled in the called procedure.
    Is this what you are trying to do?
    CREATE OR REPLACE PACKAGE p_tst
    AS
       PROCEDURE p_public;
       ex_failed   EXCEPTION;
    END;
    CREATE OR REPLACE PACKAGE BODY p_tst
    IS
       PROCEDURE p_private
       IS
       BEGIN
          RAISE ex_failed;
       END p_private;
       PROCEDURE p_public
       IS
       BEGIN
          p_private;
       EXCEPTION
          WHEN ex_failed
          THEN
             DBMS_OUTPUT.put_line ('error');
       END p_public;
    END;
    SQL> set serveroutput on;
    SQL> exec p_tst.p_public;
    error
    PL/SQL procedure successfully completed.

  • In OSB, Single business service to handle multiple Stored procedures

    Hi,
    In OSB we have a package and within that there are 8 overloaded stored procedures. DO we have to create 8 business services or is it possible to create single business service and pass differrent messages to it.
    Thanks,
    Vinoth

    Hi Vinoth,
    You have to create 8 dbadapters and hence 8 business services. Better you create one stored procedure which internally calls these 8 stored procedures on the basis of conditions you have and create only one DB adapter and hence one business service to invoke this sinlge stored procedure.
    Regards,
    Anuj

  • How to implement Exception Handling for soap to RFC sync interface...

    Dear Experts,
    we have an interface like soap to Rfc sync, already develepment is done and moved to production. but we are getting some quatitity is greater than item then it is throwing an error below. i want to handle that exception in XI level.
    please guide i am not found any document for this type of interface.
    Please suggest what can i do for this. Please share me the screen shot for this.
    Error Log:
      <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Request Message Mapping
      -->
    - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
      <SAP:Category>Application</SAP:Category>
      <SAP:Code area="RFC_ADAPTER">APPLICATION_ERROR</SAP:Code>
      <SAP:P1 />
      <SAP:P2 />
      <SAP:P3 />
      <SAP:P4 />
      <SAP:AdditionalText />
      <SAP:ApplicationFaultMessage namespace="urn:sap-com:document:sap:rfc:functions">Z_DEPOT_DISPATCH.Exception</SAP:ApplicationFaultMessage>
      <SAP:Stack />
      <SAP:Retry>M</SAP:Retry>
      </SAP:Error>
    <rfc:Z_DEPOT_DISPATCH.Exception xmlns:rfc="urn:sap-com:document:sap:rfc:functions"><Name>RFC_ERROR_SYSTEM_FAILURE</Name><Text>Delivery quantity is greater than target quantity 10.000 MT</Text><Message><ID>VL</ID><Number>363</Number></Message><Attributes><V1>10.000</V1><V2>MT</V2></Attributes></rfc:Z_DEPOT_DISPATCH.Exception>
    Regards,
    Kiran Polani

    Dear All,
    This is clearly soap to rfc interface and we are using currently PI 7.0. This is a validation of BAPI, BAPI is not accepting the field of "Quantity is some value". The quatity is greater than the amount BAPI is throwing an error like "APPLICATION_ERROR". Is it possbile to validate in XI Level.
    Soap --> XI--> BAPI(Request)
    BAPI--> XI-->Soap(Response)( in this step what ever message return by bapi those error message not getting 3 rd party application).
    here by catching that error and i should throw to 3rd party application.
    is it possible to handle this or not.?
    If it is possible in Fault Mapping/Fault message type please give me the steps or document for me.
    I am new for fault mapping?
    Please help me on this.
    Regards,
    Kiran Polani

  • CCM enrichment BaDI implementation - exception handling

    Hello CCM Gurus,
    We're using CCM 2.0 version. I'd like to make an upload enrichment implementation, and raise an exception if one item has some problem. Every time if in the code an exception is raised according to one item, the whole catalog upload goes wrong, and the upload of the other good items go wrong as well. If it is possible I'd like to get a warning or an error message in SLG1 from the problematic items, but the correct items should be load into the catalog.
    If you have a sample implementation like this, what is solved this issue please send me.
    Thanks and regards
    Almos

    Hello Masa,
    Thanks for the helpful advice, the debugging is working now. Do you know some documentation or material where I can find some useful detailed infomation about using CCM BAdI?
    I don't know exactly the differences between the /CCM/CTLG_ENRICHMENT and the /CCM/CHAR_VALUATION BAdI. What is the prefered BAdI when you'd like to change or append uploaded CCM catalog data?
    Thanks and regards
    Almos

  • Exception while calling stored procedure in SQL server

    Hi,
    I run into a problem while calling a proc in SQL server. I am using a database control to do so. The proc returns a integer. This is the first time I use SQL server. Any thoughts? Thanks in advance.
    My method call is:
    int createAccount(SQLParameter[] param)
    The sql is:
    {call espsiCompany(?, ?, ?)}
    The error is:
    java.lang.NullPointerException
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getStatement_v2(DatabaseControlImpl.jcs:1885)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.invoke(DatabaseControlImpl.jcs:2691)
    at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:373)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:423)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:396)
    at com.bea.wlw.runtime.jcs.container.JcsProxy.invoke(JcsProxy.java:388)
    at services.OnyxDBControl.createAccount(OnyxDBControl.ctrl)
    at services.OnyxDBControlTest.createAccount(OnyxDBControlTest.jws:18)

    Hi. That's not the signature of the procedure. What I'd like to see is
    the SQL used to create the procedure, eg:
    create procedure myProc @foo int, @bar varchar(30) ....
    as
    begin
    end
    Jun Li wrote:
    Here you go. Thanks for your time.
    DECLARE @RC int
    DECLARE @iSiteId int
    DECLARE @iCompanyId int
    DECLARE @chLanguageCode char(4)
    DECLARE @vchAssignedId varchar(255)
    DECLARE @vchCompanyName varchar(255)
    DECLARE @vchAddress1 varchar(255)
    DECLARE @vchAddress2 varchar(255)
    DECLARE @vchAddress3 varchar(255)
    DECLARE @vchCity varchar(255)
    DECLARE @chRegionCode char(4)
    DECLARE @chCountryCode char(4)
    DECLARE @vchPostCode varchar(40)
    DECLARE @vchPhoneNumber varchar(40)
    DECLARE @vchEmailAddress varchar(255)
    DECLARE @vchURL varchar(255)
    DECLARE @iCompanyTypeCode int
    DECLARE @iCompanySubTypeCode int
    DECLARE @iFamilyId int
    DECLARE @iParentId int
    DECLARE @iPrimaryContactId int
    DECLARE @vchContactFirstName varchar(255)
    DECLARE @vchContactLastName varchar(255)
    DECLARE @iDivisionCode int
    DECLARE @iSICCode int
    DECLARE @iMarketSector int
    DECLARE @vchTaxId varchar(255)
    DECLARE @vchDunnsNumber varchar(255)
    DECLARE @iPhoneTypeId int
    DECLARE @iAddressTypeId int
    DECLARE @iSourceId int
    DECLARE @iStatusId int
    DECLARE @bValidAddress tinyint
    DECLARE @iAccessCode int
    DECLARE @bPrivate tinyint
    DECLARE @vchUser1 varchar(255)
    DECLARE @vchUser2 varchar(255)
    DECLARE @vchUser3 varchar(255)
    DECLARE @vchUser4 varchar(255)
    DECLARE @vchUser5 varchar(255)
    DECLARE @vchUser6 varchar(255)
    DECLARE @vchUser7 varchar(255)
    DECLARE @vchUser8 varchar(255)
    DECLARE @vchUser9 varchar(255)
    DECLARE @vchUser10 varchar(255)
    DECLARE @chInsertBy char(10)
    DECLARE @dtInsertDate datetime
    DECLARE @tiLockRecord tinyint
    DECLARE @tiRecordStatus tinyint
    DECLARE @tireturnType tinyint
    -- Set parameter values
    EXEC @RC = [ONYXPROD].[dbo].[espsiCompany] @iSiteId, @iCompanyId OUTPUT , @chLanguageCode, @vchAssignedId, @vchCompanyName, @vchAddress1, @vchAddress2, @vchAddress3, @vchCity, @chRegionCode, @chCountryCode, @vchPostCode, @vchPhoneNumber, @vchEmailAddress, @vchURL, @iCompanyTypeCode, @iCompanySubTypeCode, @iFamilyId, @iParentId, @iPrimaryContactId, @vchContactFirstName, @vchContactLastName, @iDivisionCode, @iSICCode, @iMarketSector, @vchTaxId, @vchDunnsNumber, @iPhoneTypeId, @iAddressTypeId, @iSourceId, @iStatusId, @bValidAddress, @iAccessCode, @bPrivate, @vchUser1, @vchUser2, @vchUser3, @vchUser4, @vchUser5, @vchUser6, @vchUser7, @vchUser8, @vchUser9, @vchUser10, @chInsertBy, @dtInsertDate, @tiLockRecord, @tiRecordStatus, @tireturnType

  • Configuring Exception Handling CAF Guided Procedure

    Hi everybody,
    which types of callable objects can define exceptions?  I found an tutorial where Background Callable Object and External Service (BAPI/RFC) can define exceptions, but is it also possible for composite services or WebServices?
    And how could I configure a WebService as a background Callable Object?
    Thanks!
    Stefan

    Hi Stefan,
    WebService Callable Object defines exception for sure! It has to be define in the WSDL though.
    To define a WS Callable Object, you can have a look at <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/44/4758351fcb1193e10000000a155369/frameset.htm">SAP Help</a>
    Hope this helps,
    David

  • RAISING EXCEPTION AND SHOWING TO USERS IN FORM BASED ON STORED PROCEDURE

    I have a form based on stored procedure.
    I want to handle exceptions in the stored procedure and show it to users.
    Here is what i want to do.
    I have a sku# field in the form and i want to validate it(against the database
    table) in the procedure before inserting into the database.
    I want to give a message to users when the validation fails.
    How is this possible with the forms based on stored procedure?
    Can i use javascript to do the same?
    Thanks in Advance

    I have a form based on stored procedure.
    I want to handle exceptions in the stored procedure and show it to users.
    Here is what i want to do.
    I have a sku# field in the form and i want to validate it(against the database
    table) in the procedure before inserting into the database.
    I want to give a message to users when the validation fails.
    How is this possible with the forms based on stored procedure?
    Can i use javascript to do the same?
    Thanks in Advance

Maybe you are looking for

  • How to Move My Library to a New Location

    The title is a bit misleading.  This is actually related to a previous discussion I started but never got any feedback on. Here is the situation: I have iTunes Match. For whatever reason, my iTunes library got hopelessly muddled and confused.  Probab

  • After wakeup from stanby mode cannot open firefox

    I put my desktop computer running XP in standby mode overnight. When I wake it up in AM Firefox will not open when I click on the icon. I have to restart my computer in order to use Firefox

  • Configuring optimizeit profiler for multiple kjs

    Hi, I am facing problems in configuring optimizeit profiler for multiple kjs. It works fine if i have a single kjs in my app server and i am able to read the profiler output. I am using iAS6.0sp2. When i try to change the script that attaches the pro

  • How can I turn off the blobs that keep popping up with underlined or otherwise marked words or expressions in text or menue.

    Looking at web pages some key words are underlined or marked. Moving the cursor across them brings out a flag with directions to ask what it is. It is very annoying and I spend more time trying to get rid of them than enjoying the reading. This was n

  • ENABLING OF AUDIT LOGS

    I enabled audit logging on our SAP Development using transaction sm19 and noticed that the log files residing on the OS file system: /usr/sap/DEV/DVEBMGS00/log growing rather fast. This is for Development only, If I enable it on Production the growth