Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Q]What are EXCEPTIONS?

Former Member
0 Kudos

Q]What are EXCEPTIONS?

Are they real objects in ABAP

What is its use?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

There are two main types of exceptions: those that can be handled and those that cannot be handled.

· Exceptions that can be handled occur in error situations in the runtime environment or in the ABAP program, where the program can continue executing after the ABAP program has handled the exception, without the system ending up in a critical state. If such an exception is not handled, a runtime error occurs.

· The second type of exceptions are those that cannot be handled. These are critical error situations in the runtime environment. Handling with ABAP means is not possible and they always cause a runtime error.

When you create an exception for a method, you can decide if you want to use the classical exceptions or the new class-based exceptions in the method. When you use the class-based method, exceptions are represented with objects of exception classes at runtime.

Prerequisites

The method for a class or interface was already created.

Procedure

To create an exception for a method:

Place the cursor on the name of the corresponding method in the method display of the Class Editor.

Choose Exceptions.

If you want to define normal exceptions for the method, enter the following:

- Exception

Specify a suitable name for the exception. You must adhere to the naming conventions for exceptions under ABAP objects.

- Description

Short description of the exception.

If you want to create a class-based exception, first activate the Exception classes checkbox and then enter the appropriate exception class(es) under Exception. Once you have pressed ENTER , the Class Builder checks if the specified exception classes really exist. If a class does not exist, you can create it at this time. Otherwise the class description is copied.

See also:

Defining Exception Classes-http://help.sap.com/saphelp_nw70/helpdata/en/92/823e6017aa11d5969b00a0c94260a5/content.htm

Implementing Methods-http://help.sap.com/saphelp_nw70/helpdata/en/18/773e18778211d1b4510000e8a52bed/content.htm

Cheers,

vasavi.v

4 REPLIES 4

ak_upadhyay
Contributor
0 Kudos

Hi,

Creating Exceptions for Methods

Use

When you create an exception for a method, you can decide if you want to use the classical exceptions or the new class-based exceptions in the method. When you use the class-based method, exceptions are represented with objects of exception classes at runtime.

Prerequisites

The method for a class or interface was already created.

Procedure

To create an exception for a method:

Place the cursor on the name of the corresponding method in the method display of the Class Editor.

Choose Exceptions.

If you want to define normal exceptions for the method, enter the following:

- Exception

Specify a suitable name for the exception. You must adhere to the naming conventions for exceptions under ABAP objects.

- Description

Short description of the exception.

If you want to create a class-based exception, first activate the Exception classes checkbox and then enter the appropriate exception class(es) under Exception. Once you have pressed ENTER , the Class Builder checks if the specified exception classes really exist. If a class does not exist, you can create it at this time. Otherwise the class description is copied.

Reward points if useful....

Regards

AK

Former Member
0 Kudos

Hi,

Exceptions are situations that occur while an ABAP program is being executed, in which normal continuation of the program does not make any sense. Exceptions can be raised either implicitly in the ABAP runtime environment or explicitly in the ABAP program. For example, division by zero leads to an exception in the ABAP runtime environment. It is possible to determine this situation through a query in the ABAP program and to trigger an exception there.

There are two main types of exceptions: those that can be handled and those that cannot be handled.

· Exceptions that can be handled occur in error situations in the runtime environment or in the ABAP program, where the program can continue executing after the ABAP program has handled the exception, without the system ending up in a critical state. If such an exception is not handled, a runtime error occurs.

· The second type of exceptions are those that cannot be handled. These are critical error situations in the runtime environment. Handling with ABAP means is not possible and they always cause a runtime error.

As of Release 6.10, exceptions and their handling are generally based on exception classes. This concept covers the functions of the preceding concepts, enhances them, and thus replaces them.

Please go through this link.................

http://help.sap.com/saphelp_nw70/helpdata/en/02/c4e6aa19e911d5969b00a0c94260a5/content.htm

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/f86c9290-0201-0010-7a93-dda...

if its useful reward points

Former Member
0 Kudos

Hi,

There are two main types of exceptions: those that can be handled and those that cannot be handled.

· Exceptions that can be handled occur in error situations in the runtime environment or in the ABAP program, where the program can continue executing after the ABAP program has handled the exception, without the system ending up in a critical state. If such an exception is not handled, a runtime error occurs.

· The second type of exceptions are those that cannot be handled. These are critical error situations in the runtime environment. Handling with ABAP means is not possible and they always cause a runtime error.

When you create an exception for a method, you can decide if you want to use the classical exceptions or the new class-based exceptions in the method. When you use the class-based method, exceptions are represented with objects of exception classes at runtime.

Prerequisites

The method for a class or interface was already created.

Procedure

To create an exception for a method:

Place the cursor on the name of the corresponding method in the method display of the Class Editor.

Choose Exceptions.

If you want to define normal exceptions for the method, enter the following:

- Exception

Specify a suitable name for the exception. You must adhere to the naming conventions for exceptions under ABAP objects.

- Description

Short description of the exception.

If you want to create a class-based exception, first activate the Exception classes checkbox and then enter the appropriate exception class(es) under Exception. Once you have pressed ENTER , the Class Builder checks if the specified exception classes really exist. If a class does not exist, you can create it at this time. Otherwise the class description is copied.

See also:

Defining Exception Classes-http://help.sap.com/saphelp_nw70/helpdata/en/92/823e6017aa11d5969b00a0c94260a5/content.htm

Implementing Methods-http://help.sap.com/saphelp_nw70/helpdata/en/18/773e18778211d1b4510000e8a52bed/content.htm

Cheers,

vasavi.v

Former Member
0 Kudos

Hi,

Dealing with Exceptions

Exceptions are situations that occur while an ABAP program is being executed, in which normal continuation of the program does not make any sense. Exceptions can be raised either implicitly in the ABAP runtime environment or explicitly in the ABAP program. For example, division by zero leads to an exception in the ABAP runtime environment. It is possible to determine this situation through a query in the ABAP program and to trigger an exception there.

There are two main types of exceptions: those that can be handled and those that cannot be handled.

· Exceptions that can be handled occur in error situations in the runtime environment or in the ABAP program, where the program can continue executing after the ABAP program has handled the exception, without the system ending up in a critical state. If such an exception is not handled, a runtime error occurs.

· The second type of exceptions are those that cannot be handled. These are critical error situations in the runtime environment. Handling with ABAP means is not possible and they always cause a runtime error.

As of Release 6.10, exceptions and their handling are generally based on exception classes. This concept covers the functions of the preceding concepts, enhances them, and thus replaces them.

Creating Exceptions for Methods

Use

When you create an exception for a method, you can decide if you want to use the classical exceptions or the new class-based exceptions in the method. When you use the class-based method, exceptions are represented with objects of exception classes at runtime.

Prerequisites

The method for a class or interface was already created.

Procedure

To create an exception for a method:

Place the cursor on the name of the corresponding method in the method display of the Class Editor.

Choose Exceptions.

If you want to define normal exceptions for the method, enter the following:

- Exception

Specify a suitable name for the exception. You must adhere to the naming conventions for exceptions under ABAP objects.

- Description

Short description of the exception.

If you want to create a class-based exception, first activate the Exception classes checkbox and then enter the appropriate exception class(es) under Exception. Once you have pressed ENTER , the Class Builder checks if the specified exception classes really exist. If a class does not exist, you can create it at this time. Otherwise the class description is copied.

Syntax for TRY .. ENDTRY construct

TRY.

CALL METHOD o1->m1.

PERFORM f1.

CATCH cx_root. "Handler for all exceptions

" ABAP code(What to do when error occures)........

ENDTRY.

FORM f1 RAISING cx_my.

TRY.

IF ...... RAISE EXCEPTION TYPE cx_my2. ENDIF.

CALL METHOD o1->m3.

CATCH cx_my1 cx_my3 INTO ex.

RAISE EXCEPTION TYPE cx_my4.

CATCH cx_my4.

"Handler for exceptions of type cx_my4

" ABAP code(What to do when error occures)........

CLEANUP.

"Cleanup section, used to restore to a consistant state

" ABAP code........

ENDTRY.

ENDFORM.

Thanks&regards,

Sravani.