Try...Except - Help displaying more info

Hello,

I’m trying to display more information from an Exception in a messageBox instead of the Ignition error window. The java.lang Exception is from execSProcCall but in that stored procedure I’m raising specific errors in my T-SQL logic. The message I want to display is caused by a GatewayException but I don’t know how to get that value. Here is my code:

from java.lang import Exception

if event.keyCode == event.VK_ENTER:
	try:		
		call = system.db.createSProcCall("dbo.usp_Handle_Badge_Swipe")
		call.registerInParam(1, system.db.TINYINT, event.source.parent.Badge_ID)
		system.db.execSProcCall(call)
	except Exception, value:
		from com.inductiveautomation.ignition.client.gateway_interface import GatewayException
		system.gui.messageBox("Error: %s" % value) #I want the GatewayException value, not the Exception value here

This returns a messageBox with what’s expected - “Error: java.lang.Exception: Error executing system.db.execSProcCall()”. But what I’m after is the following error raised in my stored procedure and I don’t know the syntax to get it:

Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Badge 123456 is not valid for any user.

Thanks in advance,
Steve

Note the “Caused by”.[quote=“scicco”]Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Badge 123456 is not valid for any user.[/quote]That’s the key to your problem. Java exceptions can have nested exceptions as their ‘cause’. So you should be doing something like:if event.keyCode == event.VK_ENTER: call = system.db.createSProcCall("dbo.usp_Handle_Badge_Swipe") call.registerInParam(1, system.db.TINYINT, event.source.parent.Badge_ID) try: system.db.execSProcCall(call) except Exception, value: system.gui.messageBox("Error: %s" % value.getCause())I also moved your call setup instructions outside of the try. In general, you should only wrap what you expect to handle.

Exactly what I needed - thank you!