Hi, this should be a very easy question but I'm ha...
# suitescript
r
Hi, this should be a very easy question but I'm having trouble finding an answer in SuiteScript docs: how do you do a try/catch block in SS2.0? I saw one example of catch(e instanceof error.SuiteScriptError) but that doesn't seem to work
b
basically dont do what you are trying to do
r
Hmm...well I'm not using 2.1 and I'm not trying to do a conditional try/catch, so I'm not sure that answer works for me. Is it not possible to do a try/catch at all using SuiteScript?
b
works the same way as normal javascript
r
Yeah and I tried implementing it the same way, but there's no error object. In catch(e), e is undefined and so I'm not able to properly handle the error, not knowing what kind of error it is
s
I've never had a problem using the regular
try{}catch(e){}
syntax, e should definitely exist.
b
unless someone is insane and throwing undefined, e shouldnt be undefined
so what are you doing to determine what e is
r
try{}catch(e){log.debug('Execution error', e);}
Just trying to log the object in order to inspect
b
log the type of e
typeof e
Object.prototype.toString.call(e)
also works for complex cases
s
e.message
typically gives enough information in the case of suitescript as well
r
It really is just undefined. I'm using the SuiteScript debugger at the moment, and as soon as the catch block is entered, 'e' is undefined. I'm unable to call typeof, e.message, etc.
OK, I think I figured out how this works. I can log e.message. That exists
What I can't do is call e.message from the SuiteScript Debugger watches because e is undefined, or at least I'm not able to access it that way
@battk @Sandii thanks for your help!