Handling Exceptions from Java

Some Java classes throw an exception upon failure. It is recommended to catch the exception and handle it, otherwise it causes the adapter to terminate unexpectedly.

When catching a known exception, in most cases you should print its stack trace to the log and issue a proper message to the UI.

Note It is very important to import the Java base exception class as shown in the following example due to the presence of the base exception class in Python with the same name.

from java.lang import Exception as JException
try:
	client = Framework.createClient(Framework.getTriggerCIData(BaseClient.CREDENTIALS_ID))
except JException, ex:
	# process java exceptions only
	Framework.reportError('Connection failed')
	logger.debugException(str(ex))
        return

If the exception is not fatal and the script can continue, you should omit the call for the reportError() method and enable the script to continue.

Parent topic: Create Jython Code