- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 09:07 AM
Hi,
I can't catch this stupid error :
Let's say I initialize this GlideRecord in a stupid way. When calling setValue method throws an error that I am not able to catch.
Why ? Thanks
// ----------------------------------------------------------------------
var gr=new GlideRecord(null); // Missing table name
try
{
gr.setValue(100,"toto");
}
catch(e)
{
gs.log("Never goes here.");
}
// ----------------------------------------------------------------------
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 09:18 AM
Hi,
That's because no error is thrown? I believe.
You can try:
// ----------------------------------------------------------------------
var gr=new GlideRecord(null); // Missing table name
gr.query();
try
{
gr.setValue(100,"toto");
}
catch(e)
{
gs.log("Never goes here.");
}
// ----------------------------------------------------------------------
So I added in a gr.query(); to now get it going.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 09:18 AM
Hi,
That's because no error is thrown? I believe.
You can try:
// ----------------------------------------------------------------------
var gr=new GlideRecord(null); // Missing table name
gr.query();
try
{
gr.setValue(100,"toto");
}
catch(e)
{
gs.log("Never goes here.");
}
// ----------------------------------------------------------------------
So I added in a gr.query(); to now get it going.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 09:55 AM
Hi,
Yea and really I'd think you'd want to "try" it all, so this would work too:
try
{
var gr=new GlideRecord(null); // Missing table name
gr.query();
gr.setValue(100,"toto");
}
catch(e)
{
gs.info("Never goes here.");
}
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 10:41 AM
Hi,
Yea, you could also move all of the code inside the try, and then that works too:
// ----------------------------------------------------------------------
try
{
var gr=new GlideRecord(null); // Missing table name
gr.query();
gr.setValue(100,"toto");
}
catch(e)
{
gs.log("Never goes here.");
}
// ----------------------------------------------------------------------
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 11:34 AM
Lots of replies saying to do what I did lol...if anyone wants to mark Helpful...that'd be fantastic 😉
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!