Exception Handling in Peoplesoft

Exception Handling in Peoplesoft

Exception handling is the processing you initiate when an exception occurs. You can handle errors in PeopleCode using the Catch statement. The places in your code where you want exceptions handled must be enclosed by the Try and End-Try statements.

The Exception class encapsulates exceptional runtime conditions. It can be used with most PeopleCode programs.

The process of error handling can be broken down as follows:

• An error occurs (either a hardware or software error).

• The error is detected and an exception is thrown (either by the system or by your program).

• Your exception handler provides the response.

You can create exceptions in 2 ways

1) Creating an Exception base class that encapsulates the built-in function call and handles its function parameters consistently. This is the preferred way.

2) Calling the built-in function CreateException.

Application code often continues some form of processing even in the event of an exception; you should not assume that the script all processing if an exception occurs.

The error message that PeopleTools displays might not be appropriate for end-users because of its technical information.

The Exception class does not work with any of the PeopleSoft APIs, that is, the classes whose objects are declared as type ApiObject. This includes the Tree classes, the Query classes, Search classes, and so on.


Protected StatementList

catch QualifiedID &Id



Example 1:-

Import ExceptionPackage:*; 
try               /* Code to manipulate &MyArray here */
 &MyArray = GetArrayData(&Param1, &Param2, &Param3); 
catch ExceptionNull &Ex1
 If &Ex1.MessageSetNumber = 2 and &Ex1.MessageNumber = 236 Then 
   /* this is the message set and message number for &MyArray being Null */ 
   /* do data error handling */


Example 2:-
Local Exception &ex;  
Function t1(&i As integer) Returns number 
   Local number &res = &i / 0;     
Function t2 
   throw CreateException (2, 160, "'%1' doesn't support property or method '%2'", "SomeClass", "SomeMethod"); 
/* this will cause a divide by 0 leading to an exception. This code will never be caught since t1(2) will resume execution in the catch block below. It is here to show how an exception can be thrown directly bythe Peoplecode itself. */
  t2 ();   
Local number &res = t1 (2); 
Catch Exception &caught 
   MessageBox (0, "", 0, 0, "Caught exception: " | &caught.ToString()); 

Posted by