0

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!

0

1 Answer 1

1

In javascript you can throw exception from Anywhere:

Read MDN:throw

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

Sign up to request clarification or add additional context in comments.

3 Comments

There is no "javascript". The documentation of one ECMAScript implementation (here: Mozilla JavaScript) is usually not helpful in solving a problem with another one (here: Google V8 JavaScript).
@PointedEars: Have you checked the links? Are you sure that the pointed documents don't help the OP in understanding error handling? OP is interested in understanding error handling in Javascript (colloquial)
The OP is asking about node.js and need to get their basics right first. The question should have never been asked as it is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.