Exception Class in Object Oriented Programming

 

  • Exception is a problem that arises during execution of the program.
  • The purpose of exception class is to raise and handle the exception.
  • We use try block to raise a exception and catch block to handle a exception.
  • The exception class name must start with CX.
  • CX_ROOT is the global class ( parent class ) for all the exceptions.

  • There are 3 subclasses of parent class CX_ROOT.

    1. CX_STATIC_CHECK :- It is checked by both the compiler and runtime system.
    2. CX_DYNAMIC_CHECK :- It is checked only at runtime system.
    3. CX_NO_CHECK :- It is not checked either during compile time and runtime.


Note :-

  • While creating the exception class, system by default provides CX_STATIC_CHECK as the super class.

Ways to Create Exception Class :-

  • There are 2 ways to create the exception class.
    1. Exception class with messages of message class.
    2. Exception class without messages of message class.

Creating Exception Class without using messages :-

  • Step 1 :- Go to transaction code SE24.

  • Step 2 :- Give a name for your exception class.



  • Step 3 :- Click on create button.

  • As soon as you will click on create button, SAP will automatically provide CX_STATIC_CHECK as the superclass for our exception class.



    • Give short description and enable checkboxes according to your need.
    • Click on save button and assign packages and transport requests.
    • Many attributes from super class will be inherited automatically.
  • Step 4 :- In texts tab we will be proving a exception id.



  • Step 5 :- Open the attributes tab, you will find a constant attribute declared automatically.



    • Save and activate the class.

How to check this Class?

  • We have a function module SOTR_GET_TEXT_KEY.
  • Execute this Function module from SE37 and provide the initial value of above constant attribute.


  • Press F8.



  • We will see more features of exception class in next part.

Comments

Popular posts from this blog

Understanding Different Types of SAP Function Modules: Normal, RFC, and Update

Unlocking SAP ABAP Secrets: Interactive Classical Reports with GET CURSOR, At User Command, and a Comparison of HIDE Statements

Mastering ABAP: A Step-by-Step Guide to Function Modules and Groups for Modularized Programming