Show TOC

Procedure documentationException Handling Locate this document in the navigation structure

 

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

Exception Handling

Syntax Syntax

JCo 2.x

  1. public void executeFunction(JCO.Function function, String where)
  2. {
  3.     JCO.Client client = JCO.getClient(where);
  4.     client.execute(function);
  5. }
End of the code.

Syntax Syntax

JCo 3.0 (Option 1)

  1. public void executeFunction(JCO.Function function, String where)
  2.     throws JCoException
  3. {
  4.     JCoDestination destination=JCoDestinationManager.getDestination(where);
  5.     function.execute(destination);
  6. }
End of the code.

Syntax Syntax

JCo 3.0 (Option 2)

  1. public int executeFunction(JCO.Function function, String where)
  2. {
  3.     int returnCode=0;
  4.     try
  5.     {
  6.         JCoDestination destination=JCoDestinationManager.getDestination(where);
  7.         function.execute(destination);
  8.     }
  9.     catch (AbapException ex)
  10.     {
  11.         handleAbapException(function, ex);
  12.         returnCode=1;
  13.     }
  14.     catch (JCoException ex)
  15.     {
  16.         logSystemFailure(ex);
  17.         returnCode=2;
  18.     }
  19.     return returnCode;
  20. }
End of the code.