Skip to content
Advertisement

Are Promises in JavaScript like Exception Handling in Java?

Just like the try(), catch() and throw() in Java as an exception handling is like then() and catch() in JavaScript as a promise!? Just a beginner asking some questions. Please don’t judge. xD

Advertisement

Answer

try/catch detect the error itself and transfer control to catch part. this syntax exists in js too.

but in then/catch, you must notify occurring an error yourself (with calling reject). This means you can notify error when you recognize an error is occurred. that error can be a real or not real error (programming/logical error).

Advertisement