How to catch a named query error?

Hello!
I am having an issue catching a named query error. I can see the error if I'm in the named query editor while testing but if I try to duplicate the same error in the actual application my try catch does not seem to work. I have tried to implement other similar solutions on this forum like Try Catch Block is not Working for any query type like NamedQuery - Ignition - Inductive Automation Forum and some others. However, they don't seem to work for me.

I am not trying to catch a specific error I just want to throw a popup for my user with the reason. I will show my code and named query below.
SCRIPT:

def runAction(self, event):
	RC = self.parent.getChild("FlexContainer").getChild("FlexContainer").getChild("FlexContainer_0").getChild("EmbeddedView_0").props.params.CurrentText
	ICP = self.parent.getChild("FlexContainer").getChild("FlexContainer").getChild("FlexContainer_1").getChild("EmbeddedView_0").props.params.value.iconPath
	DC = self.parent.getChild("FlexContainer").getChild("FlexContainer").getChild("FlexContainer_2").getChild("EmbeddedView_0").props.params.value.color
	name = self.parent.getChild("FlexContainer").getChild("FlexContainer").getChild("FlexContainer").getChild("EmbeddedView_0").props.params.CurrentText + '-'+str(self.view.params.CellSuffix)
	RDT = self.parent.getChild("FlexContainer").getChild("FlexContainer").getChild("FlexContainer_3").getChild("EmbeddedView_1").props.params.SelectedOption
	PDT = self.parent.getChild("FlexContainer").getChild("FlexContainer_0").getChild("FlexContainer").getChild("EmbeddedView_0").props.params.SelectedOption
	OS = self.parent.getChild("FlexContainer").getChild("FlexContainer_0").getChild("FlexContainer_0").getChild("EmbeddedView_1").props.params.SelectedOption
	SRO = -1
	STID = self.parent.getChild("FlexContainer").getChild("FlexContainer_0").getChild("FlexContainer_2").getChild("EmbeddedView_0").props.params.SelectedOption
	DCC = self.parent.getChild("FlexContainer").getChild("FlexContainer_0").getChild("FlexContainer_3").getChild("EmbeddedView_0").props.params.SelectedOption
	params = {'LineID':self.view.params.LineId,'ReasonCode':RC,'IconPath':ICP,'DisplayColor':DC,'Description':name,'AltCode':-1,'RDT':RDT,'PDT':PDT,'OS':OS,'SRO':SRO,'STID':STID,'DCC':DCC}
	system.perspective.print(params)
	try:
		output = system.db.runNamedQuery('Cells/AddCellState', params)
		system.perspective.print(output)
	except java.lang.Throwable, e:
		if "Cannot insert duplicate key in object" in str(e.cause):
			pass
		else:
			raise e
	except Exception as e:
		print("Error details:", str(e))

Named Query:

EXEC [config].[stp_addEditLineState]
	@LineID = :LineID,
	@ReasonCode = :ReasonCode,
	@IconPath = :IconPath,
	@DisplayColor = :DisplayColor,
	@Description = :Description,
	@AltCode = :AltCode,
    @RecordDowntime = :RDT,
    @PlannedDowntime = :PDT,
    @OperatorSelectable = :OS,
    @SubReasonOf = :SRO,
	@StateTypeID = :STID,
	@DowntimeCategoryCode = :DCC

The specific error I was testing in my named query test was having duplicate reason codes. my database has a column constraint to prevent duplicated reason codes. So '@ReasonCode'('RC' in script) cannot be a duplicate.

EDIT: my stored procedure has no error handling; I have also verified the named query works as long as there is no duplicate key error

system.db.runNamed query returns how many rows are affected, inserted, etc on an Update. If it returns 0, you can probably assume that the RC is duplicated if that's the only rule in your table.

this is a good point this will probably be the implementation if no other points are brought up.