Jump to content
GreenSock

edbras

onError handler ?

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

How can I set a (global) onError handler/listener such that I am informed about exceptions that occur during tween updates?

Sorry, it might be in the doc's but I couldn't find it.

- Ed

Link to comment
Share on other sites

There is no such thing as a global onError because:

  1. It could significantly slow things down. try/catch blocks are notoriously S-L-O-W.
  2. Frankly, I've never needed that, nor has anyone requested it (that I can remember at least). If you're worried about creating tweens that generate errors, it's good to use something like Chrome Dev Tools and watch for them, but honestly they're pretty rare unless you try tweening a non-existent property or a null target, but those would generate errors anyway which you can easily detect in Dev Tools (or similar). 
  3. We try very hard to keep the file size to an absolutely minimum, so we don't want to sprinkle a bunch of error-sensing (and responding) code into the core.

You're welcome to add try...catch blocks around the main rendering loops in GSAP, but I really wouldn't recommend that due to the performance penalty. 

  • Like 3
Link to comment
Share on other sites

Thanks for the clear insight. I wasn't aware of this impact.

Didn't know that try/catch was so slow in JS...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×