Is it always a good practice to have your business rule code in try catch blocks ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 09:41 AM
Please can anyone let me know if it is always a good practice to wrap all code in try catch blocks in business rules in servicenow...
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 11:10 PM
Amen, no more try catch please...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 10:45 AM
Hi,
try Catch mechanism is suggested when you want to re execute some logic by using conditions like do while. This is majorly used for web services calls or in scenarios when you try to play with the session of user.
A good example is impersonating a user in "try", performing logging in "catch" and then re impersonate to self in "finally"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 10:55 AM
In client scripts it allows your scripts to fail and not make all your client scripts fail.
In business rules, they don't have the same dependencies on other scripts but the overhead of the a try/catch is something but how much can it be to suggest "not" using them? a.munoz & rajeshmushke
Insteresting related things Why isn't Try/Catch used more often in JavaScript? - Stack Overflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2025 12:25 PM
This is old, but I was looking up links to add into best practices and came across this.
I disagree if you are adding custom coding logic to the platform it is best to wrap in a try/catch. It's useful for when you are trouble shooting not only your own code but when something goes wrong as a way to track when users use the customizations in unexpected ways.