# return method stack on error?

**URL:** https://forum.servoy.com/t/return-method-stack-on-error/13129
**Category:** Classic Servoy
**Created:** [November 1, 2010, 1:15pm UTC](https://forum.servoy.com/t/return-method-stack-on-error/13129 "2010-11-01T13:15:08Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)
#### Post date: [November 1, 2010, 1:15pm UTC](https://forum.servoy.com/t/return-method-stack-on-error/13129/1 "2010-11-01T13:15:08Z")

</div>

Hi all,

We use a global method to handle all errors that occur in the solution.  
If an error occurs we create a record in a logtable so we’ll be able to get a better idea of what a user runs into.  
We already store information about the context (forms/mode/record id etc. ) the solution was in when the error occurred.

An even better logging could be achieved if we could have a look at the method stack at that particular moment.  
Is there any chance this info can be retrieved?

Thnkx

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [November 2, 2010, 1:03pm UTC](https://forum.servoy.com/t/return-method-stack-on-error/13129/2 "2010-11-02T13:03:54Z")

</div>

for rhino/scripting exceptions you can do:

ex.getScriptStackTrace()

but this will not work for all kind of exceptions you could get.

i could add for 6 also that one for ServoyExceptions, but that will not give back the script stack as above (that info is only there in script exceptions)

---

<div class="post-metadata">

### Author: ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)
#### Post date: [November 2, 2010, 2:14pm UTC](https://forum.servoy.com/t/return-method-stack-on-error/13129/3 "2010-11-02T14:14:16Z")

</div>

thnkx Johan, this will help a lot!!!

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [November 2, 2010, 2:22pm UTC](https://forum.servoy.com/t/return-method-stack-on-error/13129/4 "2010-11-02T14:22:47Z")

</div>

in 6 we already now have getStackTrace() for none script exceptions  
so there you can do now

```auto
var trace = "";
if (ex.getScriptStackTrace) trace = ex.getScriptStackTrace();
else if (ex.getStackTrace) trace = ex.getStackTrace();

```

so with the first you get the actual script stack trace and with the second the java full blown stacktrace.

---

<div class="post-metadata">

### Author: ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)
#### Post date: [November 2, 2010, 3:06pm UTC](https://forum.servoy.com/t/return-method-stack-on-error/13129/5 "2010-11-02T15:06:13Z")

</div>

> jcompagner:  
> so with the first you get the actual script stack trace and with the second the java full blown stacktrace.

blow me away! ![:wink:]( "Wink")

Just implemented the first part and that gives me already good detailed information.  
Please remind me to implement the new stuff in 6 once it’s released… ![:lol:]( "Laughing")

---

<div class="post-metadata">

### Author: ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)
#### Post date: [November 9, 2010, 9:34am UTC](https://forum.servoy.com/t/return-method-stack-on-error/13129/6 "2010-11-09T09:34:56Z")

</div>

> mboegem:  
> Just implemented the first part and that gives me already good detailed information.

Now that I’m running this code in smartclient I don’t get the stacktrace returned using ex.getScriptStackTrace();.  
When I run the same method including error in debug client it works fine.

Is this expected behaviour or did I miss something?

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [November 9, 2010, 10:08am UTC](https://forum.servoy.com/t/return-method-stack-on-error/13129/7 "2010-11-09T10:08:08Z")

</div>

i guess we are then in compiled mode and rhino can’t then give you that information.  
i guess the stack trace that you maybe see in the log has those “c1” (or c2, any number) classes in its trace?

---

<div class="post-metadata">

### Author: ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)
#### Post date: [November 9, 2010, 10:27am UTC](https://forum.servoy.com/t/return-method-stack-on-error/13129/8 "2010-11-09T10:27:38Z")

</div>

don’t know exactly what you mean with c1/c2.

This is what the debug client returns on the error:  
org.mozilla.javascript.EcmaError: ReferenceError: “x” is not defined. (C:\Servoy\_All\Workspaces\5.0.0\_dev\navigation\globals.js#664)

```auto
	at C:\Servoy_All\Workspaces\5.0.0_dev\navigation\globals.js:664 (nav_dc_add)
	at C:\Servoy_All\Workspaces\5.0.0_dev\crm\forms\Address_methods.js:190 (onSort)
	at C:\Servoy_All\Workspaces\5.0.0_dev\crm\forms\Address_stbl.js:16 (onSort)

```

Anyway, it would be very nice to have this kind of information returned in normal clients as well.  
This will help a lot to find out where the user went wrong.  
A lot of our methods are called from other methods, this can be numberous levels deep. Every level of course depending on its own arguments.

---

<div class="post-metadata">

### Author: ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)
#### Post date: [July 10, 2012, 5:55am UTC](https://forum.servoy.com/t/return-method-stack-on-error/13129/9 "2012-07-10T05:55:31Z")

</div>

Hi guys,

Is there a way to get the method call stack at any given moment at runtime without throwing an error?  
I’d like to log the stack trace when I audit fields in my app but I’m not sure how to get it (he script stack trace, not java).

Cheers!  
Maria
