# Returning backtrace from failed system.db.execSProcCall(call)

**URL:** <https://forum.inductiveautomation.com/t/returning-backtrace-from-failed-system-db-execsproccall-call/106537>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [May 21, 2025, 9:04pm UTC](https://forum.inductiveautomation.com/t/returning-backtrace-from-failed-system-db-execsproccall-call/106537 "2025-05-21T21:04:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jarvis.coghlin](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@jarvis.coghlin](https://forum.inductiveautomation.com/u/jarvis.coghlin)\
**Post date:** [May 21, 2025, 9:04pm UTC](https://forum.inductiveautomation.com/t/returning-backtrace-from-failed-system-db-execsproccall-call/106537/1 "2025-05-21T21:04:56Z")

</div>

Hello,

When calling `system.db.execSProcCall(call)` with incorrect parameters to the procedure, the stacktrace produces a generic `java.lang.Exception: Error executing system.db.execSProcCall()`  
To find the underlying reason that the SP call failed, I need to log the exception to ignition, and look at the backtrace.

I understand that this is a Java backtrace, not a Jython one, but I would like to return the backtrace to the calling function so it knows how the SP called failed, and not have to go to the logs to find out why. Is this possible?

I checked [this](https://forum.inductiveautomation.com/t/printing-stack-trace-to-gateway-logs-from-a-try/77776) post, as well as the SDK docs with no luck.

Below is an example snippet for clarification. I would like to extract the backtrace from `e`

```python
import java.lang.Exception

try:
  call = system.db.createSProcCall("pr_someProc")
  call.registerInParam("column1", system.db.NVARCHAR, value1)
  call.registerInParam("column2", system.db.NVARCHAR, value2)
  call.registerInParam("column3", system.db.NVARCHAR, value3)
  call.registerReturnParam(system.db.INTEGER)
		
  system.db.execSProcCall(call)
		
except java.lang.Exception, e:
	system.util.getLogger("genericlogger").error("FailedSPCall", e)
    # extract the backtrace from e
    return e.someFunc()

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 22, 2025, 1:00pm UTC](https://forum.inductiveautomation.com/t/returning-backtrace-from-failed-system-db-execsproccall-call/106537/2 "2025-05-22T13:00:55Z")

</div>

Java exceptions have a field for `cause`, which can be chained. For best results, just return `e` and let the caller follow the chain.

---

<div class="post-metadata">

**Author:** ![jarvis.coghlin](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@jarvis.coghlin](https://forum.inductiveautomation.com/u/jarvis.coghlin)\
**Post date:** [May 23, 2025, 4:59pm UTC](https://forum.inductiveautomation.com/t/returning-backtrace-from-failed-system-db-execsproccall-call/106537/3 "2025-05-23T16:59:34Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 23, 2025, 5:48pm UTC](https://forum.inductiveautomation.com/t/returning-backtrace-from-failed-system-db-execsproccall-call/106537/4 "2025-05-23T17:48:56Z")

</div>

Returning an error ? I don't think I've ever seen that since C style error codes

I'd re raise it, it seems more intuitive. Or am I missing something ?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 23, 2025, 5:53pm UTC](https://forum.inductiveautomation.com/t/returning-backtrace-from-failed-system-db-execsproccall-call/106537/5 "2025-05-23T17:53:11Z")

</div>

Depends on circumstances, like messaging.

---

<div class="post-metadata">

**Author:** ![jarvis.coghlin](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@jarvis.coghlin](https://forum.inductiveautomation.com/u/jarvis.coghlin)\
**Post date:** [May 27, 2025, 8:56pm UTC](https://forum.inductiveautomation.com/t/returning-backtrace-from-failed-system-db-execsproccall-call/106537/6 "2025-05-27T20:56:26Z")

</div>

Using `return e.cause.toString()` worked perfectly, and so I can return an explanation to the caller:

```json
com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert the value NULL into column 'column1', table 'table1'; column does not allow nulls. INSERT fails.

```
