notesonly.in

One notebook for every subject — open it anywhere.

Log in

Exception handling

Object-Oriented Programming · Engineering

Study notes

Read a file: try open('data.txt'); catch FileNotFoundError: print('Missing, using defaults'); finally close(). Without handling, the program crashes. With it, graceful degradation. Custom: class InvalidAgeError(Exception); raise it when age < 0; caller catches specifically. Never catch bare Exception silently.

← Back to topics for Engineering