Original Message:
Sent: Tue July 22, 2025 10:35 AM
From: Theo Pozzy
Subject: Unable to catch java exceptions in automation script
Thank you for the information about the Java exception class. Can you share an example that shows how to use the class around a Java method call?
Thank you!
------------------------------
Theo Pozzy
Original Message:
Sent: Tue July 22, 2025 10:13 AM
From: Jason Uppenborn
Subject: Unable to catch java exceptions in automation script
Java and Python both have an Exception class. What your code is catching is the Python Exception.
To resolve this conflict, import the Java Exception with an alias, like this:
from java.lang import Exception as JavaException
Then, have an except clause for each of Exception and JavaException.
------------------------------
Blessings,
Jason Uppenborn
Sr. Technical Maximo Consultant
Cohesive
Original Message:
Sent: Mon July 21, 2025 10:38 AM
From: Theo Pozzy
Subject: Unable to catch java exceptions in automation script
I have an automation script that I am working on that implements a REST API request. I'm having a problem trapping exceptions coming from java method calls. In this case, I am calling the add() method on an mbo opened on the PLUSDESTVERSION table. There is a custom java validation that throws an exception if the value assigned to the WORKGROUP field isn't a valid record. I have added multiple levels of "try/except" blocks around the add() call, but the except blocks aren't getting invoked, and my REST API call is returning a 400 status, with the response JSON body set to the data from the java error.
Here is the code:
try:
version = versionSet.add()
version.setValue("CONTRIBUTIONMETHOD", "N")
version.setValue("APPLYCONTRIBUTION", "N")
log("Before setValue(WORKGROUP)")
try:
version.setValue("WORKGROUP", parentWO.getString("OWNERGROUP"))
except Exception as addEx:
log_error("EXCEPTION during version.setValue(): {}".format(str(addEx)))
raise Exception("EXCEPTION during version.setValue(): {}".format(str(addEx)))
log("After setValue(WORKGROUP)")
version.setValue("OVERHEADTYPE", parentWO.getString("OPSSITEID"))
if ogsLvInitiatedCue == "Y":
version.setValue("STORELOC", storeLoc)
if opsSiteId == "ONG":
# Set default for ONG only
log("Setting PLUSDESTVERSION.OGSREIMBURSABLE for ONG")
version.setValue("OGSREIMBURSABLE", "No")
versionSet.save()
except Exception as addEx:
log_error("EXCEPTION during versionSet.add(): {}".format(str(addEx)))
raise Exception("EXCEPTION during versionSet.add(): {}".format(str(addEx)))
Rather than my exception message appearing in the REST call's response body, I'm getting this:
{
"Error": {
"errorattrname": "workgroup",
"extendedError": {
"moreInfo": {
"href": "http://localhost/maximo/api/error/messages/BMXAP0395E"
}
},
"correlationid": null,
"errattrvalue": null,
"reasonCode": "BMXAP0395E",
"message": "BMXAP0395E - Person Group OTRE is not a valid TnD Work Group.",
"statusCode": "400"
}
}
My log messages are also not getting written to SystemOut.log.
Is what I am doing correct? Or are automation scripts unable to trap exceptions from calls to IBM java classes?
------------------------------
Theo Pozzy
------------------------------