Writing automation scripts in Maximo is easy and almost every Maximo specialist has some ort of skills to develop customizations using Python/Jython scripts. Every error in your code will be handled by Maximo and displayed to end user as an error message. However, in some cases you need to handle exceptions in order to explicitly manage errors.
Lets consider this little piece snippet of code
woSet = mbo.getMboSet("ALLWO")
wo = woSet.getMbo(0)
wonum = wo.getString("WONUM")
woSet.close()
The mbo here refers to an ASSET and the ALLWO relationship is used to get the woSet MboSet with all work orders related to the asset. The script then fetches the WONUM of the first record in the MboSet.
Now if the ALLWO MboSet is empty the wo variable will be null and the third line of code will fail with the following error.

Python try/except blocks are natively available in automation scripts to manage exceptions. Here is how to use them in our example.
try:
woSet = mbo.getMboSet("ALLWO")
wo = woSet.getMbo(0)
wonum = wo.getString("WONUM")
woSet.close()
except:
service.error("CX", "GenericError", ["No work order found"])
Now the error message is much better than before.

We still have a problem. If the exception is raised on the wo.getString(“WONUM”) line, the woSet.close() statement will not be executed and the MboSet will never be closed. We can use the finally block in this case.
try:
woSet = mbo.getMboSet("ALLWO")
wo = woSet.getMbo(0)
wonum = wo.getString("WONUM")
except:
service.error("CX", "GenericError", ["No work order found"])
finally:
woSet.close()
Java Exceptions
In some cases you may need to explicitly catch Java exceptions. In the example below (if there is at least one work order) the line in bold will raise a Java exception, because the “xxxxWONUM” attribute does not exists, and so the “Java exception” message will be displayed.
from java.lang import Exception as JavaException
try:
woSet = mbo.getMboSet("ALLWO")
wo = woSet.getMbo(0)
wonum = wo.getString("xxxxWONUM")
except Exception:
service.error("CX", "GenericError", ["Python exception"])
except JavaException as addEx:
service.error("CX", "GenericError", ["Java exception"])
finally:
woSet.close()
