When catching JavaExceptions, i often tend to use Throwable instead of Exception. Some external libs extends its Exceptions from it.
So i end up more with this:
from java.lang import Throwable
logger = mbo.getMboLogger()
try:
logger.debug("Do something that could throw an exception")
except Exception as e:
logger.error("Python Exception: {}", str(e))
except Throwable as e:
logger.error("Java Exception: {}".format(e.getMessage()), e)
------------------------------
Andreas Brieke
IT Service Management Consultant
SVA System Vertrieb Alexander GmbH
------------------------------
Original Message:
Sent: Tue July 22, 2025 10:59 AM
From: Jason Uppenborn
Subject: Unable to catch java exceptions in automation script
When I need to catch a Java exception, it often looks like this:
from java.lang import Exception as JavaExceptionlogger = mbo.getMboLogger()try: logger.debug("Do something that could throw an exception")except Exception as e: logger.error("Python Exception: {}", str(e))except JavaException as e: logger.error("Java Exception: {}".format(e.getMessage()), e)
------------------------------
Blessings,
Jason Uppenborn
Sr. Technical Maximo Consultant
Cohesive
------------------------------
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