Skip to Content
Author's profile photo Former Member

Handling Exceptions in Custom Adapter Module in PI

This blog will explain the method to propagate your own custom error text on the communication channel monitor logs and to the standard alert framework from Custom Adapter Module in PI 7.1.

It will also discuss on few points on general exception handling in custom adapter module.

Motivation :

Lets consider , we have a requirement where the custom adapter module had to raise an exception based on certain business logic.

The exception raised from the custom module should be displayed on the communication channel monitor log and the same should be propagated to the standard alert framework. So that the alert mails received should have the exact error text raised in the custom module.

Challenge :

The obvious way to address this would  be to throw a ModuleException with a custom error text in the Custom Adapter Module. However, raising a ModuleException only with your own custom text does not propagate it neither to the Communication Channel Monitor Logs nor to the standard alert framework .

The normally followed way would be to throw ModuleException object with your custom text in the exception as below :

Please see the below code snippet from the module code :

image1.JPG

Unfortunately, by using the above method neither the communication channel logs displays the raised custom text nor it is propagated to the standard alert framework. See below screenshots.

Communication Channel Monitor Logs Screenshot:

image2.JPG

If you observe the communication channel monitor log display “Error: null” rather than “Your  custom error message” which was expected.

The same text “Error: null” is passed to the alert framework, hence the same is populated in the alert mails.

Below is the screenshot from a alert mail triggered by the standard alert framework:

image3.JPG

Solution:

In-order to address the above  challenge, you can follow the below procedure.

Step 1: In addition to your module class, create your own Custom Exception class as below : 

Code snippet for creating your custom exception class.In this example I am using the custom exception class name as RecordMismatchException.

image4.JPG

Step 2:  Code snippet for raising and handling the custom exception in the adapter module class

image5.JPG

You can create your own exception class and replace the text as per your requirement.

The important point in the above code is to pass the cause while throwing a ModuleException from custom module, so that its caught by the caller of the module and is handled.


That is it ! You can now verify if it works.

Step 3 : You can now verify whether the error message raised in module is displayed on the communication channel monitor log and passed to the alert framework.

a.Communication channel monitor is displaying the required error text :

image6.JPG

b.Alert mail generated by the alert framework has the required error message :

image7.JPG

Bingo! it works . You can now see the custom text both in channel log and alert mails.

Assumption, the alert category and the alert rule is already defined in the PI system.

Note :

  1. The above procedure is tested on PI 7.1 SP5 Version with Custom Module used with the File Adapter
  2. The above procedure can also be used for throwing standard Java exception too and will not need  any Custom Exception class for it.

This is my first blog, I will be glad to know your views/suggestion or feedback on it to improve.

Hopefully, this blog will be helpful to the PI community

Assigned Tags

      12 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Shabarish Vijayakumar
      Shabarish Vijayakumar

      good info and welcome to SCN Blogs 🙂

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Shabarish and will also like take this opportunity to mention that I regularly follow your blogs and really like them.

      Author's profile photo Shabarish Vijayakumar
      Shabarish Vijayakumar

      Thanks Vishal 🙂

      Author's profile photo Former Member
      Former Member

      Nice informative blog. Good job and thanks 🙂

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Vineet

      Author's profile photo Former Member
      Former Member

      Informative and educational article.

      Author's profile photo Azhar Shaikh
      Azhar Shaikh

      Congrats on your first blog.Very descriptive and well written!

      Author's profile photo Former Member
      Former Member

      Vishal,

      Very useful information. I have followed this technique and I am seeing the exception coming through the alert framework and delivering emails. I cannot however, find a way to include/see the text of my custom exception in the body of the email as you showed in your example email text.

      Thanks.

      (editted for spelling)

      Author's profile photo Former Member
      Former Member

      Good blog Vishal 🙂

      Author's profile photo Former Member
      Former Member

      Hi Vishal,

      Fantastic blog ! Now only I saw this blog. I appreciate all your efforts.

      Keep up the good work!

      Regards,

      Hari Suseelan

      Author's profile photo Naveen Kumar Reddy chichili
      Naveen Kumar Reddy chichili

      Nice blog...!! Informative.

      Regards,

      'Naveen

      Author's profile photo Waldemar Bachmann
      Waldemar Bachmann

      Still works in 2021 on PO 7.5 🙂

      Just out of curiosity: Why the Channel Monitor shows null when throwing the exception as ModuleException but displays the message correctly, when it is thrown as custom exception?! Is it because the adapter module EJB and the custom exception are in the same package/name space and the ModuleException is not?