Yotam
Yotam

Reputation: 10485

Throw exception outside try block, nodeJS,JavaScript

Is it possible to throw an exception outside a try block? If I'm not mistaken in Java you can declare that a function throws an exception and then just throw it up the function chain, with no try/catch inside the function. Any similar method in nodeJS?

Also, I noticed that if I try to throw an exception from a callback function to where It was called in my code, I can't do it. I understand it can be solved using domains, which I still don't know. Am I right?

Thanks!

Upvotes: 0

Views: 3147

Answers (1)

closure
closure

Reputation: 7452

In javascript you can throw exception from Anywhere:

Read MDN:throw

For better understanding of error handling, see and search "error constructor"

Upvotes: 1

Related Questions