runNamedQuery returns None on all failures?

Hello,

I have an application that relies on some database feedback whenever I try to query it. I have all of my queries running through the system.db.runNamedQuery function and all is well when the query is successful. However some times the query fails and I cannot get any useful information out of it. According to the docs I see that it normally returns out the pyDataSet, which is true for my set up, but it does not mention anything about failed queries.

Hopefully I am just missing something but it appears that failed queries just return None.

A quick look at docs and implementation suggest it can throw an Exception.

What is a "failed query" in your case?

I have the following code where the query has some constraints around whether "thing 1" can be added to "thing 2", those are all handled in the database at the moment and I would like to be able to display the reasoning sent from the database

try:
    res = system.db.runNamedQuery('insert-thing-into-thing', params)
    producedUUIDs.append(res)
except:
	self.props.text = res
	functions.show_error_popup('ERROR', res)

Try catching exceptions like this:

I'm realizing that I was trying to do too many things within that 1 query and that I need to separate out the verification portions into other queries that I can be more verbose with the query results. Thanks for the fast response!

PS. @pturmel uses java.lang.Throwable now, I believe, which Exception inherits from. Although, it looks like Error and Exception inherit from Throwable, where the description in Error says code shouldn't usually try to catch and handle these errors :man_shrugging:

1 Like