Wednesday, April 22, 2015

Custom PeopleSoft Exceptions

Application Package

I created an application package with a couple classes but I soon realized I needed different exceptions for different behaviours.  This is easy in JAVA you just build a custom exception that extends the exception class.  I figured there must be similar way to do this in poeplesoft but couldn't find an example in peoplebooks they seem to always just use the "CreateException" method.  This example will give you the ability to throw and catch different custom exceptions.


Application Package

MY_PERSON_SYNC
  • MY_PersonBuilder
  • MY_PersonSync
  • MYPersonException

Exception Class

This first step is create your Exception.  I put mine as a different class in the same package that will be throwing it.  This class will extend exception and only have the basic constructor method in it.  This constructor will create the super class Exception using the common peoplesoft method CreateException.  I accepted only the message as a string but you could accept your own custom message numbers as well if you like.


class MYPersonException extends Exception
   method MYPersonException(&MSG As string);
end-class;

method MYPersonException
   /+ &MSG as String +/
   %Super = CreateException(0, 0, &MSG);
end-method;

Person Builder Class
Next in my class MY_PersonBuilder I need I have 2 different errors.  The first is one that I will issue a standard exception that should really stop the process all together.  The second is for when the problem could only be related to a single individual and if multiple transactions are being processed only reject this one transaction.


import MY_PERSON_SYNC:MYPersonException;
...
/* If it is an SQL error you might throw standard Exception */
&recResult = &rec.Update();
If &recResult = false Then
    throw CreateException(0, 0, "update to table **NOT** successful for %1", &rec.ID.Value);
End-If;

/* If my error was specific to a single transaction I would throw my custom Exception */
throw create MY_PERSON_SYNC:MYPersonException("Person missing a Xref value. ");

Person Sync Class
The class MY_PersonSync actually implements the class PS_PT:Integration:INotificationHandler so it has a OnNotify method where the try catch will exist. This is the location that determines if an error should be thown stopping the entire process or just drop a single transaction and continue to process the remaining ones.

import MY_PERSON_SYNC:MYPersonException;
...
   try
      &personBuilder.AddPersonAudit();
      &psXrefId = &personBuilder.AddXrefPS();
      &newid = &personBuilder.GenerateNewID("", False);
      &EMSTXrefId = &personBuilder.AddXrefEMST();
      &alias = &personBuilder.AddIdAlias(&newid);
   catch MY_PERSON_SYNC:MYPersonException &exPerson
      MessageBox(0, "", 0, 0, &exPerson.ToString());
   catch Exception &exError
      Error &exError.ToString();
   end-try

1 comment: