Global Exception Class
Hi,
I have a global exception class which is inherited from already existing exception class.
I would like to use this class to raise different exceptions.
How to use this global exception class to raise exceptions with different descriptions?
can anybody explain or send a material on this?
Thanks in advance...
Sreenivas Reddy
I guess you have little misunderstanding of the Exception concept.
You have to RAISE the exception from any processing block (Subroutine, Method etc.) and CATCH the exception in where you call the subroutine.
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.
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->devide
EXPORTING
n1 = lf_n1
CHANGING
n2 = lf_n2.
* catching the exception
CATCH zcx_gen_exc INTO lo_exc.
MESSAGE lo_exc->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
Regards,
Naimesh Patel
Similar Messages
-
Hi,
What is exception class .
What is local exception class
what is global exception class.
Thanks,
Medha.Hi,
And also check this doc.
http://help.sap.com/saphelp_nw04/helpdata/en/fb/35c62bc12711d4b2e80050dadfb92b/content.htm
a® -
hi all ,,
can any one tell me how to create a exception class in ABAP OOPS concept ??
if possible can give link also for documentHI Jayakumar,
Please go thru this document
Exceptions are represented by objects that are instances of exception classes. Defining an exception is, therefore, the same as creating an exception class.
All exception classes must inherit from the common superclass CX_ROOT and one of its subordinate classes:
CX_STATIC_CHECK
CX_DYNAMIC_CHECK
CX_NO_CHECK
. The assignment of exception classes to one of these three paths of the inheritance hierarchy determines the way in which the associated exceptions are propagated. There is a record of predefined exception classes CX_SY_... whose exceptions are raised in error situations in the runtime environment. These classes all inherit from CX_DYNAMIC_CHECK or CX_NO_CHECK but not from CX_STATIC_CHECK (see hierarchy in the ABAP keyword documentation).
All exception classes must begin with the prefix CX_. They are usually defined globally with the Class Builder of the ABAP Workbench. Local exception classes can, however, also be defined.
Individual (abstract) exception classes that are used as the superclass of further exception classes can be defined. The exceptions of the subordinate classes can be handled together using a superclass.
Exception classes have the following features:
Constructor
The constructor must have a predefined structure and a specific interface. With global classes, the Class Builder generates the correct constructor and sets it to an unchangeable status. The constructor has two IMPORTING parameters:
TEXTID of the SOTR_CONC type
This parameter can be used to determine which of your exception texts the exception will use.
PREVIOUS of the CX_ROOT type
This parameter can be used to assign the PREVIOUS attribute a previous exception.
Methods
In exception classes, you can define your own methods. The following two predefined methods are inherited from the root class CX_ROOT:
GET_TEXT
Sends back the exception texts of a class (controlled by the TEXTID attribute) as a string.
GET_SOURCE_POSITION
Returns the program name, the name of a possible include program, and the line number of the statement that raised the exception.
Attributes
The attributes of exception classes are used to transport additional information on an error situation to the handler. The main piece of information is, however, always the fact that an exception of a particular class has occurred. The following attributes are inherited from CX_ROOT:
TEXTID
Used to specify the exception of a class more precisely by using several exception texts. Is evaluated in the GET_TEXT method.
PREVIOUS
If an exception is mapped to another exception, a reference to the original exception can be defined in this attribute via the EXPORTING addition of the RAISE EXCEPTION statement and by means of the constructor IMPORTING PARAMETER with the same name. This can result in a chain of exception objects. In the event of a runtime error, the exception texts of all the exceptions in the chain are output. Mapping an exception to another exception is only beneficial if the context in which the original exception occurred is important for characterizing the error situation.
KERNEL_ERRID
The name of the associated runtime error is stored in this attribute if the exception was raised by the runtime environment, for example, COMPUTE_INT_ZERODIVIDE with a division by zero. If the exception is not handled, precisely this runtime error occurs.
Parameters cannot be transferred to the constructor for this attribute. If the exception is raised with RAISE EXCEPTION, the attribute is set to initial.
Global Exception Classes
Global exception classes are defined and managed in the Class Builder. If the correct naming convention (prefix CX_) and the class type Exception Class is chosen when a new class is created, the Class Builder automatically becomes the Exception Builder.
The Exception Builder offers precisely the functionality required to define exception classes and generates independently-defined components that must not be changed. When classes are created, the category of the exception must be specified, in other words, whether it is to inherit from CX_STATIC_CHECK, CX_DYNAMIC_CHECK, or CX_NOCHECK.
Tab Pages of the Exception Builder
The Exception Builder has the tab pages Properties, Attributes, Methods, and Texts.
The properties do not normally need to be changed.
Except for the four inherited attributes mentioned above, further public attributes can be generated by the Exception Builder. The contents of these attributes specify the exception more clearly and manage the exception texts.
All of the methods are inherited from CX_ROOT. New methods cannot be added. The instance constructor is generated automatically. It ensures that, when an exception is raised, the attributes have the right values. It also transfers the text of the superclass for an exception class whose exception text is not specified explicitly.
The instance constructor is generated on the basis of the attributes, which are set up on the basis of the exception texts. Changing the attributes in superclasses can, therefore, invalidate the constructors of subordinate classes. The constructors of subordinate classes can be regenerated under Utilities ® CleanUp ® Constructor.
Texts are a special feature of exception classes and the Exception Builder. For further information, refer to Exception Texts.
Local Exception Classes
Local exception classes can be defined for specific exceptions that only occur within one single ABAP program. The condition for a local exception class is that it inherits from one of the three classes CX_STATIC_CHECK, CX_DYNAMIC_CHECK, or CX_NO_CHECK, or from their subordinate classes. An individual constructor and individual attributes can be created. Individual methods should not be created, however, and the methods of superclasses should not be redefined.
Examples of Local Exception Classes
report DEMO_LOCAL_EXCEPTION_1.
class CX_LOCAL_EXCEPTION definition
inheriting from CX_STATIC_CHECK.
endclass.
start-of-selection.
try.
raise exception type CX_LOCAL_EXCEPTION.
catch CX_LOCAL_EXCEPTION.
message 'Local Exception!' type 'I'.
endtry.
This example shows a minimal local exception class, which is simply the local representation of one of the three direct subordinate classes of CX_ROOT. It can be used in the program.
report DEMO_LOCAL_EXCEPTION_2.
class CX_LOCAL_EXCEPTION definition
inheriting from CX_STATIC_CHECK.
public section.
data LOCAL_TEXT type STRING.
methods CONSTRUCTOR importing TEXT type STRING.
endclass.
class CX_LOCAL_EXCEPTION implementation.
method CONSTRUCTOR.
SUPER->CONSTRUCTOR( ).
LOCAL_TEXT = TEXT.
endmethod.
endclass.
data OREF type ref to CX_LOCAL_EXCEPTION.
start-of-selection.
try.
raise exception type CX_LOCAL_EXCEPTION
exporting TEXT = `Local Exception`.
catch CX_LOCAL_EXCEPTION into OREF.
message OREF->LOCAL_TEXT type 'I'.
endtry.
In this example, the exception class from the previous example is extended to include an individual attribute and constructor. The IMPORTING parameter of the constructor must be supplied when the exception is raised (it is required here). The attribute can be evaluated in the handler of the exception.
report DEMO_LOCAL_EXCEPTION_3.
class CX_LOCAL_EXCEPTION definition
inheriting from CX_SY_ARITHMETIC_ERROR.
public section.
methods CONSTRUCTOR importing SITUATION type STRING.
endclass.
class CX_LOCAL_EXCEPTION implementation.
method CONSTRUCTOR.
SUPER->CONSTRUCTOR( OPERATION = SITUATION ).
endmethod.
endclass.
data OREF type ref to CX_LOCAL_EXCEPTION.
data TEXT type STRING.
start-of-selection.
try.
raise exception type CX_LOCAL_EXCEPTION
exporting SITUATION = `START-OF-SELECTION`.
catch CX_LOCAL_EXCEPTION into OREF.
TEXT = OREF->GET_TEXT( ).
message TEXT type 'I'.
endtry.
In this example, an exception class is derived from one of the predefined exception classes for error situations in the runtime environment. An individual constructor is defined with an individual IMPORTING parameter that supplies the superclass constructor with this parameter. When the exception is handled, the exception text, as defined in the superclass, is read with GET_TEXT. -
Hi All,
When ever there is an error I need to handle the exceptions gracefully. Since I'm using struts frame work I'm using global-exceptions declarative.
Here is the struts-config.xml where I have included <global-exceptions>
<global-exceptions>
<exception handler="com.hp.chrs.action.ActionExceptionHandler"
type="java.lang.Exception"
key="global.error.message "
path="/jsp/chrs_error.jsp" />
</global-exceptions>
I have written ActionExceptionHandler.java class which is the subclass of ExceptionHandler. In execute function of this I'm logging the error then forwarding it to chrs_error.jsp.
public ActionForward execute(Exception ex, ExceptionConfig ae,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException {
System.out.println ("Inside execute of ActionExceptionHandler");
logError(ex);
//forward to the jsp
ActionForward forward =
super.execute(ex, ae, mapping, formInstance, request, response);
When ever an error occurs chrs_error.jsp is displayed. But it is not going to ActionExceptionHandler.java class.
What my unerstanding is whenever error occurs it should go to ActionExceptionHandler and then display chrs_error.jsp.
Any inputs are welcome
Thanks in AdvanceMost probably its the wrond struts version...you cannot use message resources in struts i.0, might want to change the head of the struts-config.xml to
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> -
Is there anyway I can hook the exception class to catch any and all exceptions or basically what I am trying to do is have an error reporter class and right now I have try catch blocks in every one of my methods that then from that sends the error to the reporter class and then the reporter sends the messages to my server. Is there a better way of doing this for example some how hooking or extending the exception class?
Any other ways? I just want to see all the ways and
select the best and easiest to implement.No. There isn't any other way to setup a global error handler.
Kaj -
Hi All,
When ever there is an error I need to handle the exceptions gracefully. Since I'm using struts frame work I'm using global-exceptions declarative.
Here is the struts-config.xml where I have included <global-exceptions>
<global-exceptions>
<exception handler="com.hp.chrs.action.ActionExceptionHandler"
type="java.lang.Exception"
key="global.error.message"
path="/jsp/chrs_error.jsp" />
</global-exceptions>
I have written ActionExceptionHandler.java class which is the subclass of ExceptionHandler. In execute function of this I'm logging the error then forwarding it to chrs_error.jsp.
public ActionForward execute(Exception ex, ExceptionConfig ae,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException {
System.out.println("Inside execute of ActionExceptionHandler");
logError(ex);
//forward to the jsp
ActionForward forward =
super.execute(ex, ae, mapping, formInstance, request, response);
When ever an error occurs chrs_error.jsp is displayed. But it is not going to ActionExceptionHandler.java class.
What my unerstanding is whenever error occurs it should go to ActionExceptionHandler and then display chrs_error.jsp.
Any inputs are welcome
Thanks in AdvanceNo there isn't a global exception handler in JSF. At least none that I've ever heard of or run across. This is something I think JSF dropped the ball on. Maybe in a future release?
I'm afraid you'll have to get creative with error processing. It's tricky with JSF.
The way I did it in my application was to create error pages (as you mentioned). I configured the web.xml to redirect to these error pages if there was an uncaught exception. There are some serious limitations when you forward to a JSF page like this though. First, you need to make your error page have f:subview tags instead of f:view. Then, I couldn't get commandLink or commandButton to work right. The action method never got executed!
You may have already seen some discussions about this. If not, dig around in the forums and you'll find a few good tips.
CowKing -
Get the values from Exception class
Hi all ..
In class i have raised one exception
when i catch this exception in my program i m able to get the
error message but i need to get all the parameters that i pass
when i raise the exception ...
i have raised like this
RAISE EXCEPTION TYPE cx_bapi_error
EXPORTING
textid = cx_bapi_error=>cx_bo_error
class_name = 'ZHS_'
log_no = wa_bapi_return-log_no
log_msg_no = wa_bapi_return-log_msg_no
t100_msgid = wa_bapi_return-id
t100_msgno = wa_bapi_return-number
t100_msgv1 = wa_bapi_return-message_v1
t100_msgv2 = wa_bapi_return-message_v2
t100_msgv3 = wa_bapi_return-message_v3
t100_msgv4 = wa_bapi_return-message_v4
STATUS = lt_status
and caught the exception like this in my program
CATCH cx_bapi_error INTO go_error.
gd_text = go_error->get_text( ).
EXIT.
ENDTRY.
in this i m just getting the class name which i have passed in exception
i need all other parameters that i have passed ..
if u have any idea pls let me know ..
Thanks in advance ...Hello Jayakumar
Usually the attributes of standard exception classes are defines as <b>public</b> and <b>read-only</b>. Thus, you should be able to use the following coding:
DATA:
go_error TYPE REF TO cx_bapi_error. " specific exception class !!!
TRY.
RAISE EXCEPTION TYPE cx_bapi_error
EXPORTING
textid = cx_bapi_error=>cx_bo_error
class_name = 'ZHS_'
log_no = wa_bapi_return-log_no
log_msg_no = wa_bapi_return-log_msg_no
t100_msgid = wa_bapi_return-id
t100_msgno = wa_bapi_return-number
t100_msgv1 = wa_bapi_return-message_v1
t100_msgv2 = wa_bapi_return-message_v2
t100_msgv3 = wa_bapi_return-message_v3
t100_msgv4 = wa_bapi_return-message_v4
STATUS = lt_status.
CATCH cx_bapi_error INTO go_error.
gd_text = go_error->get_text( ).
WRITE: go_error->t100_msgid, " perhaps the attributes have different name
go_error->t100_msgno, " check attribute names in SE24
EXIT.
ENDTRY.
Regards
Uwe -
DAC ERROR EXCEPTION CLASS::: java.lang.NullPointerException
hello guru,
when i creating a execution plan in my local envt for testing
I have assemble the subject area
but while building the execution plan i am getting below error:
SHTEST-TEST
EXCEPTION CLASS::: java.lang.NullPointerException
com.siebel.analytics.etl.execution.ExecutionParameterHelper.substituteNodeTables(ExecutionParameterHelper.java:174)
com.siebel.analytics.etl.execution.ExecutionParameterHelper.parameterizeTask(ExecutionParameterHelper.java:141)
com.siebel.analytics.etl.execution.ExecutionPlanDesigner.getExecutionPlanTasks(ExecutionPlanDesigner.java:738)
com.siebel.analytics.etl.execution.ExecutionPlanDesigner.design(ExecutionPlanDesigner.java:1267)
com.siebel.analytics.etl.client.util.tables.DefnBuildHelper.calculate(DefnBuildHelper.java:169)
com.siebel.analytics.etl.client.util.tables.DefnBuildHelper.calculate(DefnBuildHelper.java:119)
com.siebel.analytics.etl.client.view.table.EtlDefnTable.doOperation(EtlDefnTable.java:169)
com.siebel.etl.gui.view.dialogs.WaitDialog.doOperation(WaitDialog.java:53)
com.siebel.etl.gui.view.dialogs.WaitDialog$WorkerThread.run(WaitDialog.java:85)
can anyone help on this.
thanksHello Shiva,
I have tried to generate the paramenter index in going into execute tab.
Acutally I have two database one is SH(for sales fact table) as source and other is SHTST (for target w_sales_F).
when i go into that it try to click on generate button it shows only for SHTST not for SH
more over in SHTST the value is coming as Informatica folder Sales where i created all mapping.
SH and SHTST both are in same database oracle 10g.
please help -
ABAP OO Exception Class based processing
Hi there,
Note: In going forward with SAP WAS 6.20, one can handle exceptions using exception-class based handling using RAISE EXCEPTION TYPE abc and then CATCHing it in TRY/ ENDTRY block. Standard method like GET_TEXT can be used to get the text of the exception raised.
Question: If I know the EXCEPTION CLASS and Exception ID of my exception class, is it possible to get the exception text directly from the repository without creating the exception class object?
E.g. Exception class is CX_MY_SECRET_ID
and Exception IDs for this class are
ID_NOT_FOUND,
ID_EXPIRED,
ID_IS_FOR_SPECIAL_ACCESS
E.g. last two exception IDs are my warning conditions, and if such conditions are encountered, all I want to do is collect the warning messages. Whereas first exception ID condition (i.e. ID_NOT_FOUND) is an error for me, in which I have pass the exception back to the calling program. E.g. the source code is like this:
PERFORM.......
If ID is not found
RAISE EXCEPTION TYPE ZCX_MY_SECRET_ID
EXPORTING TEXT_ID = 'ID_NOT_FOUND'.
else if ID has expired
...... then do I have to first raise the exception like raised above and CATCH it before I can get its text? or can I get the exception text directly without raising the exception first (as I know i have to retrieve the text of ZCX_MY_SECRET_ID exception class for Exception ID ID_EXPIRED)?
In other words, if a certain condition is warning for my program, can I get the condition for that exception (from exception class based on exception class name and exception ID), or do I have to RAISE it first explicitely and then CATCH it immediately and execute GET_TEXT to get its text?
Thanks very much!Hello Chetan,
in basic the raise exception type xxx creates an exception object and aborts normal execution continuing in the enclosing try block.
The Abap runtime contains some optimizations regarding the try block has an 'into xxx' clause. But as long you use the same exception you cant take benefit from this.
As far I understand your problem you have two different kind of severities. So I would use 2 differnt exception classes (maybe derived from a common parent type, or one from the other).
So both the code which throws the exception and the one which catches it are aware of the different semantic.
Kind Regards
Klaus -
Class Based Exception Handling involves raising exception (RAISE EXCEPTION TYPE), catching it (CATCH within TRY/ENTRY block) and maybe execute GET_TEXT method to get the text for that exception.
Allowing exception texts be stored as part of exception classes, does that mean that SAP is moving away from using SAP Message Class (transaction SE91 messages) and relying now onwards upon storing texts in respective Exception Clases?
My understanding is that SE91 holds not only the texts for exceptions (or hard errors) but also informational and warning messages, and hence if program condition has to display an informational or warning message, there is not need to create an Exception Class for such a condition (and then get the TEXT for that informational message from that Exception Class). Right?
Pls explain. Thanks much.Hi Chetan,
Sap is not moving away from T100-based (SE91) messages at all.
In fact you do not store exceptions texts in exception classes but in the OTR (Online Text Repository) and still in T100. If an exception class implements the interface IF_T100_MESSAGE (as of Release 6.40), you can use the statement
MESSAGE excref TYPE ...
to display the message after
CATCH INTO excref.
It is recommended to use T100-messages for texts send to the user via MESSAGE and OTR-texts for texts not sent to the user but used internally, e.g. for writing into logs.
Regards
Horst -
How to set up global exception handling to provide user friendly messages to user?
AFAIK there is no real global exception handing available for now in ADF. So I need some "tutorials" about exception handling in:
- Model
- Controller
- View
Thx
Regards
Zmedarefer this
http://blogs.oracle.com/groundside/entry/adventures_in_adf_logging_part
controller
http://blogs.oracle.com/jdevotnharvest/entry/extending_the_adf_controller_exception_handler
http://andrejusb.blogspot.com/2011/03/exception-handler-for-method-calls_19.html
http://my.safaribooksonline.com/book/databases/oracle/9780071622547/introduction-to-oracle-adf-task-flows/ch04lev1sec7
http://my.safaribooksonline.com/book/databases/oracle/9780071622547/working-with-unbounded-and-bounded-oracle-adf-task-flows/169 -
Exception class: RFC not found
Hi,
Do you know whether there is an exception class in web dynpro java that i can catch in case the RFC is not found in the backend system?
Thanks and regards,
NadaThank you!
Are the mentioned exceptions general exceptions if something is going wrong with the execute() method or they are specific for the problem 'RFC not found in the backend).
So I need this specfic information that the RFC is not found in the backend. -
Hi all,
i build exception class with massages ,and i want to know if there is log that
manage this exception ? i,e. where i can see the exception's of the program if they occur .
Best regards
NinaHi Nina,
take a look at the function modules in function group SBAL. They let you add messages to message logs which can be displayed using transaction SLG1.
You can find more information here:
[Online help for application logs|http://help.sap.com/saphelp_erp60_sp/helpdata/EN/2a/fa0216493111d182b70000e829fbfe/content.htm]
Regards,
David -
Hi,
i create exception class like it write in the sap help and when i want to send the exception with parameters to the ABOVE METHODS i don't susses i just get the message without the parameter ?
there is simple guideline how o transfer the exception with parameters?
br
RicardoHI Uwe,
Thanks,
This is my sample code:
This is the first method on the tree:
the method name is create .
INSERT (lt_table_name) FROM <ls_obj>.
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE /cx_db_db_error
EXPORTING
textid = cx_db_error=>create_failed
table_name = lt_table_name.
ENDIF.
this method call to the above method - create .
TRY.
CALL METHOD lo_obj_create->create
CHANGING
is_bound_object = ls_obj_user.
CATCH cx_db_error INTO lo_exc.
"Create user failed. Throw an exception.
RAISE EXCEPTION TYPE cx_db_error
EXPORTING
textid = cx_db_error=>create_user_error
previous = lo_exc.
result = lo_exc->get_text( ).
ENDTRY.
here in result i just get the massage without the table name that i export in the first method ,what i miss here ?
Best Regards
Ricardo -
Exception class & Throwable class
Does the Exception class inherit hashCode from the Throwable class?
thanks in advance for anyones help??No, from Object.
http://java.sun.com/products/jdk/1.2/docs/api/java/lang/Exception.html
Maybe you are looking for
-
Automatic Customer Clearing through FF_5
Hi Gurus, While uploading bank statement through FF_5, system is not clearing customer invoices automatically. Please let me know exactly what settings are missing and what should we do to implement automatic clearing of customer open item once bank
-
Using Disk Utility to restore/copy disk - who is correct?
I had two long talks with two separate Apple Care people online today who both insisted what they were saying was right and the other person was wrong. Hmm.... My question is this. I have a MBP and the internal HD is currently empty. I've been runnin
-
There was an error attaching this file
I wanted to send an email and I tried to attach a file from pages, I have tried several times but I always get "there was an error attaching this file"
-
Sliding Panels: On last panel - go to another html?
Hey everyone! My first website is coming along nicely. Though my Creative Director has asked for a nice tweak to the site and I've hit a brick wall. I've got a few product pages that's split into different categories - 8 html pages. On each page I ha
-
Ztable to be insert,modify operation through a transction
hi all, I have a ztable. Now I need to make this as transaction based, say I create a tcode ZCODE and when I execute ZCODE, I NEED TO DISPLAY ALL ENTRIES IN ztable, then I need INSERT, MODIFY,DELETE ,CREATE NEW ENTRIES button in the screen and SAVE I