How to detect client-side errors

bonsai
Mega Sage

I would like to create a process that detects when an error occurs in a UI page, UI policy, or client script.

I know that you can use "try~catch" to catch errors, but is there a way to implement this in a single client script or the like to detect errors in the browser?
I considered incorporating "try~catch" into the client-side processing, but if there is a common error collection process, I would like to implement it.

I would like to be able to catch error events, etc.

Alternatively, if I could catch some kind of event and constantly determine errors, I think I could record browser errors.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@bonsai 

the only possible way is to use try catch block and if you wish to log it in system logs then within the catch block you can use GlideAjax to write to add it in system logs using gs.info()

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@bonsai 

the only possible way is to use try catch block and if you wish to log it in system logs then within the catch block you can use GlideAjax to write to add it in system logs using gs.info()

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@bonsai 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@bonsai 

you can throw the exception and log it in browser console but it won't be stored in system logs though.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Is there a way to catch all exceptions in one client script or UI script?