- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 08:14 AM
Hi,
I had a requirement to add a throw if the app name is null and in throw i need to display catch message. can anyone pls help me how to write the throw block and display the error message from catch block. Below is the script.
try {
var recentAppJson = {};
var appName = '';
recentAppJson.success = true;
} catch (ex) {
recentAppJson.error = ex.stack;
recentAppJson.success = false;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2022 01:21 AM
Hi
basically not, but it is always the best approach to encapsulate business logic in functions (located in Script Includes).
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 08:23 AM
Hi
It seems you are not familiar with the concept of exception handling. When someone ask you to throw an exception then you should implement something like this:
function foo(strAppName) {
if (typeof strAppName != "string" || strAppName.length == 0) {
throw new IllegalArgumentException(
"Expected a non-empty 'string' argument."
);
}
}
So the caller of the function foo() is responsible to catch the exception:
try {
foo();
}
catch (e) {
gs.info(e.toString);
}
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 08:35 AM
Thanks Maik!!
Do i need to add to add function compulsory. Can you please suggest.
Regards,
Revathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2022 01:21 AM
Hi
basically not, but it is always the best approach to encapsulate business logic in functions (located in Script Includes).
Maik