<?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 Re: Global Exception Class in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540065#M1265286</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Naimesh, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  I have created a custom exception class with the attributes you have given above and these attributes &lt;/P&gt;&lt;P&gt;are available as a import parameters to the constructor class. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We cab raise an exception with some description 'Exception occured' as you have shown above. &lt;/P&gt;&lt;P&gt;Now, my requirement to catch the same exception in later part of the code and I want to get the same &lt;/P&gt;&lt;P&gt;description in the later part of the code.  I have written the code as shown below. But, I am not able to &lt;/P&gt;&lt;P&gt;get the same description. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; 

data: n1 type i value 0, 
      n2 type i value 5, 
      v_exc_text type string. 

data: v_ex_oref TYPE REF TO ZCX_SAMPLE_EXCEPTION. 

try. 
if n1 = 0. 
  RAISE EXCEPTION TYPE ZCX_SAMPLE_EXCEPTION 
    EXPORTING 
      exc_text = 'Exception occured' 
      mes_type = 'E'. 
else. 
  n2 = n2 / n1. 
endif. 

CATCH ZCX_SAMPLE_EXCEPTION into v_ex_oref. 

v_exc_text = v_ex_oref-&amp;gt;get_text( ). 

IF v_exc_text is not initial. 
   MESSAGE e000(zfi) with v_exc_text space space space. 
ENDIF. 

endtry. 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do I need to modify the code of get_text( ) method? Please suggest, how to handle this? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, &lt;/P&gt;&lt;P&gt;Sreenivas Reddy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Apr 2009 07:24:18 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-04-28T07:24:18Z</dc:date>
    <item>
      <title>Global Exception Class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540061#M1265282</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; I have a global exception class which is inherited from already existing exception class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to use this class to raise different exceptions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; How to use this global exception class to raise exceptions with different descriptions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can anybody explain or send a material on this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance...&lt;/P&gt;&lt;P&gt;Sreenivas Reddy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Apr 2009 13:15:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540061#M1265282</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-27T13:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Global Exception Class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540062#M1265283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In your global exception class create couple of attributes which you can use to provide different descriptions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For Example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
EXC_TEXT	Instance Attribute	Public	Type	STRING	Exception Text
MES_TYPE	Instance Attribute	Public	Type	CHAR1	Message Type
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once you add this attributes to your exception class, than they would be avaliable as the signature of the CONSTRUCTOR method of exception class.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, you can use this exception class raise exception like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  RAISE EXCEPTION TYPE zcx_general_exc
    EXPORTING
      exc_text = 'Exception occured'
      mes_type = 'E'.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Apr 2009 13:30:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540062#M1265283</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2009-04-27T13:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Global Exception Class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540063#M1265284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the reply...&lt;/P&gt;&lt;P&gt;No, The golobal exception class is 'CX_AI_APPLICATION_FAULT'. It is not providing the parameters with&lt;/P&gt;&lt;P&gt;that name.  Do you want me create these parameters in my custom defined global exception class?&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Do I have to pass these variables to any value in the constructor definition?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Give complete details...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Sreenivas Reddy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Apr 2009 13:41:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540063#M1265284</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-27T13:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Global Exception Class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540064#M1265285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Its entirely depends on your requriement. You can inherite a Exception class from this CX_AI_APPLICATION_FAULT or you can inherite the exception class from CX_DYNAMIC_CHECK. But there is no direct way where you can pass your description while raising the Exception CX_AI_APPLICATION_FAULT. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a general rule, you must not enhance any standard class. So, inherite a Z exception class from CX_AI_APPLICATION_FAULT and follow the instructions as per the previous post.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Apr 2009 13:54:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540064#M1265285</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2009-04-27T13:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: Global Exception Class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540065#M1265286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Naimesh, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  I have created a custom exception class with the attributes you have given above and these attributes &lt;/P&gt;&lt;P&gt;are available as a import parameters to the constructor class. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We cab raise an exception with some description 'Exception occured' as you have shown above. &lt;/P&gt;&lt;P&gt;Now, my requirement to catch the same exception in later part of the code and I want to get the same &lt;/P&gt;&lt;P&gt;description in the later part of the code.  I have written the code as shown below. But, I am not able to &lt;/P&gt;&lt;P&gt;get the same description. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; 

data: n1 type i value 0, 
      n2 type i value 5, 
      v_exc_text type string. 

data: v_ex_oref TYPE REF TO ZCX_SAMPLE_EXCEPTION. 

try. 
if n1 = 0. 
  RAISE EXCEPTION TYPE ZCX_SAMPLE_EXCEPTION 
    EXPORTING 
      exc_text = 'Exception occured' 
      mes_type = 'E'. 
else. 
  n2 = n2 / n1. 
endif. 

CATCH ZCX_SAMPLE_EXCEPTION into v_ex_oref. 

v_exc_text = v_ex_oref-&amp;gt;get_text( ). 

IF v_exc_text is not initial. 
   MESSAGE e000(zfi) with v_exc_text space space space. 
ENDIF. 

endtry. 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do I need to modify the code of get_text( ) method? Please suggest, how to handle this? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, &lt;/P&gt;&lt;P&gt;Sreenivas Reddy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2009 07:24:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540065#M1265286</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-28T07:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Global Exception Class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540066#M1265287</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I guess you have little misunderstanding of the Exception concept.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have to RAISE the exception from any processing block (Subroutine, Method etc.) and CATCH the exception in where you call the subroutine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check this example. In this example, I am raising the exception from the method DEVIDE of the class LCL_TEST. Now, I call this method DEVIDE in the START-OF-SELECTION block. So, here I need to catch this raised exception by the DEVIDE method. In my example I have used the exception class ZCX_GEN_EXC, you may have to replace it with your exception class ZCX_SAMPLE_EXCEPTION.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
CLASS lcl_test DEFINITION.

  PUBLIC SECTION.
    METHODS devide
      IMPORTING
        n1 TYPE i
      CHANGING
        n2 TYPE i
      RAISING
        zcx_gen_exc.

ENDCLASS.                    "lcl_test DEFINITION

START-OF-SELECTION.

  DATA: lo_test TYPE REF TO lcl_test,
        lo_exc  TYPE REF TO zcx_gen_exc,
        lf_n1   TYPE i,
        lf_n2   TYPE i.

  CREATE OBJECT lo_test.

  lf_n1 = 0.
  lf_n2 = 10.

  TRY.
      CALL METHOD lo_test-&amp;gt;devide
        EXPORTING
          n1 = lf_n1
        CHANGING
          n2 = lf_n2.
* catching the exception
    CATCH zcx_gen_exc INTO lo_exc.
      MESSAGE lo_exc-&amp;gt;wf_etext TYPE 'I'.
  ENDTRY.

*----------------------------------------------------------------------*
CLASS lcl_test IMPLEMENTATION.

  METHOD devide.

    IF n1 = 0.
      RAISE EXCEPTION TYPE zcx_gen_exc
        EXPORTING
          wf_etext = 'Exception occured'
          wf_mtype = 'E'.
    ELSE.
      n2 = n2 / n1.
    ENDIF.

  ENDMETHOD.                    "devide

ENDCLASS.                    "lcl_Test IMPLEMENTATION
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2009 13:32:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540066#M1265287</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2009-04-28T13:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Global Exception Class</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540067#M1265288</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Answered&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Dec 2009 10:38:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/global-exception-class/m-p/5540067#M1265288</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-12-01T10:38:31Z</dc:date>
    </item>
  </channel>
</rss>

