What is the difference between a 'throw' statement and returning an error?

Responsive Ad Header

Question

Grade: Education Subject: Support
What is the difference between a 'throw' statement and returning an error?
Asked by:
74 Viewed 74 Answers

Answer (74)

Best Answer
(322)
A 'throw' statement interrupts the normal flow of execution and signals that an error has occurred, requiring a 'catch' block to handle it. Returning an error, on the other hand, simply passes an error object back as a function's return value, and the calling code must explicitly check for and handle this returned error.