<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic exception handling in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling/m-p/2988170#M705711</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to handle the user defined exception handling.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rakesh.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 31 Oct 2007 08:53:10 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-10-31T08:53:10Z</dc:date>
    <item>
      <title>exception handling</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling/m-p/2988170#M705711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to handle the user defined exception handling.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rakesh.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2007 08:53:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling/m-p/2988170#M705711</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-10-31T08:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: exception handling</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling/m-p/2988171#M705712</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rakesh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you talking about class based exceptions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If yes.. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Class based exceptions will help us to avoid dumps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example, if we are diving something with ZERO it would go to a dump. So to avoid the same we will put the statement in TRY.. ENDTRY.. Block..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the sample code for the same.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  Y_EXCEPTION.
 
 DATA: i TYPE i VALUE 1.
 
START-OF-SELECTION.
      TRY.
        i = i / 0.
        CATCH cx_sy_zerodivide.
         write:/5 'Divide by zero caught'.
      ENDTRY.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to create your own exceptions... Below code could help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  Y_EXCEPTION.
 CLASS CX_SAMPLE_EXCEPTION DEFINITION    INHERITING FROM CX_STATIC_CHECK.
public section.
 methods : meth1.
ENDCLASS. 

CLASS CX_SAMPLE_EXCEPTION IMPLEMENTATION.
method : meth1.
 write:/5 'I am a method in exception'.
endmethod.
ENDCLASS. 

CLASS SOME_CLASS DEFINITION.
  PUBLIC SECTION.
    METHODS: m1 raising cx_sample_exception .
ENDCLASS. 

CLASS SOME_CLASS IMPLEMENTATION.
  METHOD m1.
   RAISE EXCEPTION TYPE CX_SAMPLE_EXCEPTION.
  ENDMETHOD.
ENDCLASS. 

DATA:  c1 TYPE REF TO SOME_CLASS.
 START-OF-SELECTION.
 TRY.
   CREATE OBJECT c1.
   c1-&amp;gt;m1( ).
 CATCH CX_sample_exception.
   write:/5 'Exception caught'.
 ENDTRY. 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see standard example on se38, DEMO_HANDLE_EXCEPTIONS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT DEMO_HANDLE_EXCEPTIONS.

PARAMETERS NUMBER TYPE I.

DATA RESULT TYPE P DECIMALS 2.
DATA OREF TYPE REF TO CX_ROOT.
DATA TEXT TYPE STRING.

START-OF-SELECTION.

  WRITE: / 'Testing divison and Sqare root with', NUMBER.
  ULINE.
  TRY.
    IF ABS( NUMBER ) &amp;gt; 100.
      RAISE EXCEPTION TYPE CX_DEMO_ABS_TOO_LARGE.
    ENDIF.
    TRY.
      RESULT =  1 / NUMBER.
      WRITE: / 'Result of division:', RESULT.
      RESULT = SQRT( NUMBER ).
      WRITE: / 'Result of square root:', RESULT.
      CATCH CX_SY_ZERODIVIDE INTO OREF.
        TEXT = OREF-&amp;gt;GET_TEXT( ).
      CLEANUP.
        CLEAR RESULT.
    ENDTRY.
    CATCH CX_SY_ARITHMETIC_ERROR INTO OREF.
      TEXT = OREF-&amp;gt;GET_TEXT( ).
    CATCH CX_ROOT INTO OREF.
      TEXT = OREF-&amp;gt;GET_TEXT( ).
  ENDTRY.
  IF NOT TEXT IS INITIAL.
    WRITE / TEXT.
  ENDIF.
  WRITE: / 'Final result:', RESULT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above example CX_DEMO_ABS_TOO_LARGE and CX_SY_ZERODIVIDE, CX_SY_ARITHMETIC_ERROR are standard class exceptions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sreekanth&lt;/P&gt;&lt;P&gt;*&amp;lt;i&amp;gt;Do not forget to reward if it helps you...&amp;lt;/i&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2007 15:48:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling/m-p/2988171#M705712</guid>
      <dc:creator>sreekanthgo</dc:creator>
      <dc:date>2007-10-31T15:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: exception handling</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling/m-p/2988172#M705713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We use the term exception to refer to a situation that arises while a program is&lt;/P&gt;&lt;P&gt;being executed, where there is no point in continuing to run the program in the&lt;/P&gt;&lt;P&gt;normal way. The SAP Web AS 6.10 introduced a new ABAP Objects exception&lt;/P&gt;&lt;P&gt;concept, parallel to the existing concept. Exceptions and exception handling are&lt;/P&gt;&lt;P&gt;now based on classes. This concept includes the concepts that preceded it but&lt;/P&gt;&lt;P&gt;also enhances (and thus replaces) them.&lt;/P&gt;&lt;P&gt;Class-based exceptions are raised either by the RAISE EXCEPTION statement&lt;/P&gt;&lt;P&gt;or by the runtime environment. Division by zero, for example, would be an&lt;/P&gt;&lt;P&gt;example of the latter.&lt;/P&gt;&lt;P&gt;In an exception situation, an exception is represented by an exception object -&lt;/P&gt;&lt;P&gt;that is, an instance of an exception class. The attributes of each exception object&lt;/P&gt;&lt;P&gt;contain information about the error situation.&lt;/P&gt;&lt;P&gt;When handling an exception, you can have it raise new exceptions and thus create&lt;/P&gt;&lt;P&gt;a chain of exceptions. Thus, in special cases, you can catch a runtime exception&lt;/P&gt;&lt;P&gt;and then have it raise an exception of its own.&lt;/P&gt;&lt;P&gt;You can define exception classes yourself, but there is already a range of&lt;/P&gt;&lt;P&gt;predefined exception classes in the system &amp;amp;#150; particularly for exceptions in the&lt;/P&gt;&lt;P&gt;runtime environment. You usually create exception classes globally in the Class&lt;/P&gt;&lt;P&gt;Builder, but you can also define local exception classes within a program or&lt;/P&gt;&lt;P&gt;global class.&lt;/P&gt;&lt;P&gt;The use of class-based exceptions is not limited to object-oriented contexts.&lt;/P&gt;&lt;P&gt;Class-based exceptions can be raised and handled in all processing blocks.&lt;/P&gt;&lt;P&gt;In particular, all previously catchable runtime errors can now be handled as&lt;/P&gt;&lt;P&gt;class-based exceptions.&lt;/P&gt;&lt;P&gt;If a class-based exception is raised, the system interrupts the normal program flow&lt;/P&gt;&lt;P&gt;and tries to navigate to a suitable handler. If it cannot find a handler, a runtime&lt;/P&gt;&lt;P&gt;error occurs.&lt;/P&gt;&lt;P&gt;All exception classes are derived from the one of the classes CX_NO_CHECK,&lt;/P&gt;&lt;P&gt;CX_DYNAMIC_CHECK, or CX_STATIC_CHECK, themselves derived from&lt;/P&gt;&lt;P&gt;the common superclass CX_ROOT.&lt;/P&gt;&lt;P&gt;The way in which exception classes are assigned to one of these three paths in&lt;/P&gt;&lt;P&gt;the hierarchy defines how the associated exceptions are propagated. (This will be&lt;/P&gt;&lt;P&gt;discussed in more detail later in this unit.)&lt;/P&gt;&lt;P&gt;In the SAP standard system, the names of all exception classes start with CX_.&lt;/P&gt;&lt;P&gt;The CX_ROOT class provides some predefined methods that are inherited by all&lt;/P&gt;&lt;P&gt;exception classes: The GET_SOURCE_POSITION method returns the name of&lt;/P&gt;&lt;P&gt;the main program and (if relevant) the names of the include program and the&lt;/P&gt;&lt;P&gt;line number in the source code where the exception occurred. The GET_TEXT&lt;/P&gt;&lt;P&gt;method returns an exception text in the form of a string.&lt;/P&gt;&lt;P&gt;Newly defined exception classes inherit from one of these superclasses, so that&lt;/P&gt;&lt;P&gt;other components can be added. These are usually individual exception texts.&lt;/P&gt;&lt;P&gt;You can assign several texts to each class. The IDs assigned to these are created&lt;/P&gt;&lt;P&gt;by the Class Builder as identically named static constants. You can then specify&lt;/P&gt;&lt;P&gt;which text is to be used when an exception is raised by passing one of these&lt;/P&gt;&lt;P&gt;constants to the import parameter TEXTID of the instance constructor.&lt;/P&gt;&lt;P&gt;All exception classes inherit the KERNEL_ERRID attribute from CX_ROOT.&lt;/P&gt;&lt;P&gt;This attribute contains the name of the appropriate runtime error if the exception&lt;/P&gt;&lt;P&gt;was raised by the runtime environment - such as BCD_ZERODIVIDE if the&lt;/P&gt;&lt;P&gt;program catches a CX_SY_ZERODIVIDE exception (division by zero). If the&lt;/P&gt;&lt;P&gt;exception is not listed, a runtime error occurs.&lt;/P&gt;&lt;P&gt;An exception can only be handled if the statement that could raise it is enclosed&lt;/P&gt;&lt;P&gt;in a TRY-ENDTRY block. The exception is then handled using the CATCH&lt;/P&gt;&lt;P&gt;statement in the TRY-ENDTRY block.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
CLASS lcl_plane
DEFINITION.
PUBLIC SECTION.
...
METHODS get_attributes
EXPORTING
ex_name TYPE t_name_15
value(ex_wa_plane) TYPE saplane
RAISING
cx_bc401_excd_planetype.
ENDCLASS. "lcl_plane DEFINITION
CLASS lcl_plane IMPLEMENTATION.
...
METHOD get_attributes.
SELECT SINGLE * FROM saplane
INTO ex_wa_plane
WHERE planetype = me-&amp;gt;type.
IF sy-subrc = 0.
IF ex_wa_plane-seatsmax_b = 0. "should stand for freighter here
RAISE EXCEPTION TYPE cx_bc401_excd_planetype
EXPORTING
planetype = me-&amp;gt;type
textid = cx_bc401_excd_planetype=&amp;gt;cx_bc401_excd_planetype_f.
ENDIF.
ELSE.
RAISE EXCEPTION TYPE cx_bc401_excd_planetype
EXPORTING
planetype = me-&amp;gt;type.
ENDIF.
ENDMETHOD. "lcl_plane
ENDCLASS. "lcl_plane IMPLEMENTATION
BC401
CLASS lcl_carrier DEFINITION.
PUBLIC SECTION.
...
METHODS display_attributes.
ENDCLASS. "lcl_carrier DEFINITION
CLASS lcl_carrier IMPLEMENTATION.
...
METHOD display_attributes.
DATA:
l_ref_plane TYPE REF TO lcl_plane,
l_name TYPE t_name_15,
l_wa_plane TYPE saplane,
l_ref_exc TYPE REF TO cx_bc401_excd_planetype,
l_exc_text TYPE string.
...
TRY.
CALL METHOD l_ref_plane-&amp;gt;get_attributes
IMPORTING
ex_wa_plane = l_wa_plane.
WRITE: l_wa_plane-planetype,
l_wa_plane-producer,
l_wa_plane-seatsmax_b.
CATCH cx_bc401_excd_planetype INTO l_ref_exc.
l_exc_text = l_ref_exc-&amp;gt;get_text( ).
WRITE l_exc_text COLOR COL_NEGATIVE.
ENDTRY.
ENDMETHOD. "display_attributes
ENDCLASS. "lcl_carrier IMPLEMENTATION
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if useful,&lt;/P&gt;&lt;P&gt;Aleem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2007 12:53:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling/m-p/2988172#M705713</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-01T12:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: exception handling</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling/m-p/2988173#M705714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;In an exception situation,&amp;lt;/b&amp;gt; an exception is represented by an exception object -that is, an instance of an exception class. The attributes of each exception objectcontain information about the error situation.&lt;/P&gt;&lt;P&gt;When handling an exception, you can have it raise new exceptions and thus create&lt;/P&gt;&lt;P&gt;a chain of exceptions. Thus, in special cases, you can catch a runtime exception&lt;/P&gt;&lt;P&gt;and then have it raise an exception of its own.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;"You can define exception classes yourself &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; , but there is already a range of predefined exception classes in the system &amp;#150; particularly for exceptions in the runtime environment. You usually create exception classes globally in the Class Builder, but you can also define local exception classes within a program or&lt;/P&gt;&lt;P&gt;global class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The use of class-based exceptions is not limited to object-oriented contexts.&lt;/P&gt;&lt;P&gt;Class-based exceptions can be raised and handled in all processing blocks.&lt;/P&gt;&lt;P&gt;In particular, all previously catchable runtime errors can now be handled as&lt;/P&gt;&lt;P&gt;class-based exceptions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If a class-based exception is raised, the system interrupts the normal program flow&lt;/P&gt;&lt;P&gt;and tries to navigate to a suitable handler. If it cannot find a handler, a runtime&lt;/P&gt;&lt;P&gt;error occurs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All exception classes are derived from the one of the classes CX_NO_CHECK,&lt;/P&gt;&lt;P&gt;CX_DYNAMIC_CHECK, or CX_STATIC_CHECK, themselves derived from&lt;/P&gt;&lt;P&gt;the common superclass CX_ROOT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Example: Raising, Propagating and Handling an Exception

CLASS lcl_plane
DEFINITION.
PUBLIC SECTION.
...
METHODS get_attributes
EXPORTING
ex_name TYPE t_name_15
value(ex_wa_plane) TYPE saplane
RAISING
cx_bc401_excd_planetype.
ENDCLASS. "lcl_plane DEFINITION
CLASS lcl_plane IMPLEMENTATION.
...
METHOD get_attributes.
SELECT SINGLE * FROM saplane
INTO ex_wa_plane
WHERE planetype = me-&amp;gt;type.
IF sy-subrc = 0.
IF ex_wa_plane-seatsmax_b = 0. "should stand for freighter here
RAISE EXCEPTION TYPE cx_bc401_excd_planetype
EXPORTING
planetype = me-&amp;gt;type
textid = cx_bc401_excd_planetype=&amp;gt;cx_bc401_excd_planetype_f.
ENDIF.
ELSE.
RAISE EXCEPTION TYPE cx_bc401_excd_planetype
EXPORTING
planetype = me-&amp;gt;type.
ENDIF.
ENDMETHOD. "lcl_plane
ENDCLASS. "lcl_plane IMPLEMENTATION



CLASS lcl_carrier DEFINITION.
PUBLIC SECTION.
...
METHODS display_attributes.
ENDCLASS. "lcl_carrier DEFINITION
CLASS lcl_carrier IMPLEMENTATION.
...
METHOD display_attributes.
DATA:
l_ref_plane TYPE REF TO lcl_plane,
l_name TYPE t_name_15,
l_wa_plane TYPE saplane,
l_ref_exc TYPE REF TO cx_bc401_excd_planetype,
l_exc_text TYPE string.
...
TRY.
CALL METHOD l_ref_plane-&amp;gt;get_attributes
IMPORTING
ex_wa_plane = l_wa_plane.
WRITE: l_wa_plane-planetype,
l_wa_plane-producer,
l_wa_plane-seatsmax_b.
CATCH cx_bc401_excd_planetype INTO l_ref_exc.
l_exc_text = l_ref_exc-&amp;gt;get_text( ).
WRITE l_exc_text COLOR COL_NEGATIVE.
ENDTRY.
ENDMETHOD. "display_attributes
ENDCLASS. "lcl_carrier IMPLEMENTATION
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward  points  if it is usefull.....&lt;/P&gt;&lt;P&gt;Girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2007 08:21:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/exception-handling/m-p/2988173#M705714</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-11-02T08:21:58Z</dc:date>
    </item>
  </channel>
</rss>

