# JSEvent in errorhandler in Servoy 5.0?

**URL:** <https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419>\
**Category:** Classic Servoy\
**Created:** [November 20, 2009, 10:00am UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419 "2009-11-20T10:00:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)\
**Post date:** [November 20, 2009, 10:00am UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419/1 "2009-11-20T10:00:18Z")

</div>

Just a question.

Is the JSEvent also given as parameter to the errorhandler?

In case the errorhandler is triggered, I would like to know what event has caused this error

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [November 20, 2009, 4:05pm UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419/2 "2009-11-20T16:05:18Z")

</div>

Martin,

When you assign a method to an event in Servoy 5, you can choose to create a new method.  
These methods are created according to a template that matches the signature expected for that event.

Rob

---

<div class="post-metadata">

**Author:** ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)\
**Post date:** [November 20, 2009, 4:19pm UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419/3 "2009-11-20T16:19:50Z")

</div>

Hi Rob,

I’m nore sure if you understood my question, or that I understand your reply

What I mean is that in the solution properties, you can say onError and link a global method to it (the errorhandler)  
Does this errorhandler when it is called (and this is always unexpected, never know from where it is called) also has the JSEvent as parameter, so that I can show formname, elementname, etc in the errorhandler (like I now use those application.trigger methods)

Martin

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [November 20, 2009, 4:50pm UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419/4 "2009-11-20T16:50:28Z")

</div>

Martin,

I meant as a general way to check the signature you can create a new method.

When you do this for the solution onerr method, you will see that there is just 1 arg, the exception that occurred.

Rob

---

<div class="post-metadata">

**Author:** ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)\
**Post date:** [November 21, 2009, 10:42am UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419/5 "2009-11-21T10:42:55Z")

</div>

OK,

Can it be useful to add a request to add the JSEvent also as passed argument (arg 2), or is that technically not possible?

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [December 1, 2009, 8:18am UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419/6 "2009-12-01T08:18:44Z")

</div>

Martin,

Since the exception can be thrown from anywhere, the formname, elementname, etc in an event would not be very reliable.  
If you use the application.trigger methods methods you just get the last ones used, it does not have to be the cause of the error.

Rob

---

<div class="post-metadata">

**Author:** ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)\
**Post date:** [December 1, 2009, 11:41am UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419/7 "2009-12-01T11:41:15Z")

</div>

Hi Rob,

> rgansevles:  
> If you use the application.trigger methods methods you just get the last ones used, it does not have to be the cause of the error.

I agree that this is not always the cause of the error, but showing the last form/elementname helps me to find the reason for an exception

The application.trigger methods were available on any moment in script. Even when these methods do not return a value, I could still call them and they gave me the last value if there was one.  
Since the JSEvent is passed as a parameter I would have to save this JSEvent in a global on every method that is behind an event, and in the exception check the contents of that global.  
That means a lot of scripting needs to be changed.

Maybe a new method could be a solution:

application.getLastEvent() which returns the last JSEvent object.

In that case if works similar like before with those application.trigger methods

Martin

---

<div class="post-metadata">

**Author:** ![Karel\_Broer](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Karel\_Broer](https://forum.servoy.com/u/Karel_Broer)\
**Post date:** [December 1, 2009, 6:54pm UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419/8 "2009-12-01T18:54:21Z")

</div>

> martinh:  
> Maybe a new method could be a solution:  
> application.getLastEvent() which returns the last JSEvent object.

I agree, a new method would be nice to handle the JSEvent object.  
What I would like is something like this:

```auto
var vArgs = arguments[0]
if(vArgs && vArgs.isJSEvent() == true){
 //do something
}

```

I tried typeof vArgs, but that doesn’t tell me if the passed object is a ‘real’ JSEvent… ![:wink:]( "Wink")

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [December 2, 2009, 9:10am UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419/9 "2009-12-02T09:10:54Z")

</div>

This will work:

```auto
if (arguments[0] instanceof JSEvent) {...}

```

Paul

---

<div class="post-metadata">

**Author:** ![Karel\_Broer](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Karel\_Broer](https://forum.servoy.com/u/Karel_Broer)\
**Post date:** [December 2, 2009, 11:21am UTC](https://forum.servoy.com/t/jsevent-in-errorhandler-in-servoy-5-0/11419/10 "2009-12-02T11:21:27Z")

</div>

> pbakker:  
> This will work:
> 
> ```auto
> if (arguments[0] instanceof JSEvent) {...}
> 
> ```

Nice! Thanks Paul.
