- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 08:43 PM
* This is an instance of the Paris version.
I'm thinking of writing a script to insert a record.
I want to implement exception handling with "try ~ catch",
In the following cases, no error has occurred.
(1) When a character string other than the date format is set in the field for entering the date
⇒ A blank is set in the field and no error occurs.
(2) When 100 characters are entered in the field for entering a character string with a 40-character limit.
⇒ The first 40 characters of 100 characters are set, and no error occurs.
I thought that "Type Error" would occur in case of (1) and "Range Error" would occur in case of (2).
Does anyone understand?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 08:51 PM
Hi
it seems, that you are not familar with try-catch-blocks. Please read https://www.w3schools.com/js/js_errors.asp
Basically you catch pure JavaScript errors and ServiceNow APIs only throw real errors in rare cases. Unfortunately, you have to check the failure behavior for each method of an ServiceNow-API. Sometimes they return null, sometimes empty Strings and sometimes an error is thrown.
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 08:51 PM
Hi
it seems, that you are not familar with try-catch-blocks. Please read https://www.w3schools.com/js/js_errors.asp
Basically you catch pure JavaScript errors and ServiceNow APIs only throw real errors in rare cases. Unfortunately, you have to check the failure behavior for each method of an ServiceNow-API. Sometimes they return null, sometimes empty Strings and sometimes an error is thrown.
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 09:08 PM
thank you for your answer.
I learned a lot! !!
Is there any other way to control ServiceNow's API-related errors like "Try ... Catch"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 09:16 PM
Hi
although I had not the time yes to write an article about error handling, you can see the underlying concepts in my article Universal Pattern for Script Includes
At the end it is always good to have a wrapping try-catch-block for the whole script. And within the try-block you have to handle all other error behaviors manually.
Kind regards
Maik