Introduction
Throwing exceptions helps your program handle errors in a clear way. It lets you stop normal work and jump to special error-handling code.
When a function cannot complete its task because of bad input.
When a file your program needs is missing or cannot be opened.
When a calculation results in an unexpected problem, like division by zero.
When you want to separate normal code from error-handling code for clarity.