Start of Content Area

Procedure documentation Exception Handling  Locate the document in its SAP Library structure

Use

As a result of changes to exception handling, instead of enhancing of java.lang.RuntimeException, java.lang.Exception has been introduced as a new parent class.

When using RuntimeExceptions, it was not mandatory that exceptions be added to a throws clause. However, when using 'normal' exceptions you must always decide whether an exception is to be handled explicitly or if it is to be added to the throws clause.

Prerequisites

You have not previously set any try-catch [-finally]blocks for exception handling.

Procedure

To adapt your code, either set try-catch [-finally]blocks, or add your exceptions to a throw clause.

Example

Example JCo 2.x

 

public void executeFunction(JCO.Function function, String where)

{

    JCO.Client client = JCO.getClient(where);

    client.execute(function);

}

 

 

Example JCo 3.0 (Option 1)

 

public void executeFunction(JCO.Function function, String where)

    throws JCoException

{

    JCoDestination destination=JCoDestinationManager.getDestination(where);

    function.execute(destination);

}

 

 

Example JCo 3.0 (Option 2)

 

public int executeFunction(JCO.Function function, String where)

{

    int returnCode=0;

    try

    {

        JCoDestination destination=JCoDestinationManager.getDestination(where);

        function.execute(destination);

    }

 

    catch (AbapException ex)

    {

        handleAbapException(function, ex);

        returnCode=1;

    }

    catch (JCoException ex)

    {

        logSystemFailure(ex);

        returnCode=2;

    }

    return returnCode;

}

 

 

End of Content Area