Catching Errors
Sometimes an error is expected and you want to handle it rather than crash. A file might be missing, a user might type letters into a number field, a network might be down.
Both languages wrap risky code in a try block and handle problems in a second block.
✦ Catch narrowly
Catching every possible error and ignoring it hides real bugs. Catch the specific error you expect and let anything unexpected surface. A silent program that produces wrong answers is far worse than one that stops and tells you.
Mark this lesson complete
Signed in, your progress follows you to every device.