- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 08:05 AM
Something very very weird is going on. Despite my try/catch block, the RuntimeException is still thrown and not caught... How do I catch it?
Evaluator: java.lang.RuntimeException: String object has exceeded max size of 16777216
Caused by error in script at line 18
15: var b64 = GlideBase64.encode(bytearrayOS.toByteArray());
16: try {
17: var newb64 = b64.split(String.fromCharCode(10)).join('');
==> 18: newb64 = newb64.split(String.fromCharCode(13)).join('');
19: gs.print(att.getDisplayValue() +':\n'+newb64);
20: } catch (err) {
21: gs.print('ignoring exception')
22: }
The second weird thing is, that it only triggers on line 18, but not on line 17. Why is the string not too long in line 17, but too long in line 18? It should be shorter, no?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 08:39 AM
ServiceNow backend is based on Java.
And when you are using Java's classes, such String, executing of this part is delegating on Java backend and in your case it throws RuntimeException (Java Platform SE 7 ) because String object contains an array of chars, so you can have at most 2^31 - 1 characters in a Java String. In this case, error occurs in scope which is not visible for your JavaScript try-catch.
If you throw an exception explicitly in JavaScript code block, your catch will works. You can try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 08:39 AM
ServiceNow backend is based on Java.
And when you are using Java's classes, such String, executing of this part is delegating on Java backend and in your case it throws RuntimeException (Java Platform SE 7 ) because String object contains an array of chars, so you can have at most 2^31 - 1 characters in a Java String. In this case, error occurs in scope which is not visible for your JavaScript try-catch.
If you throw an exception explicitly in JavaScript code block, your catch will works. You can try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 08:42 AM
That really sucks...