How do we classify errors based on their origin
New and bubbled-up
What are further distinction can you have for new and bubbled-up errors
Recoverable and non-recoverable
What are the 4 scenarios
Example of New Recoverable error
LBYL
def add_song_to_db(song)
if song.year is None
song.year = 'Unknown'Example of Bubbled-up recoverable error
def add_song_to_db(song):
try:
artist = get_artist_from_db(song.artist)
except NotFound:
add_artist_to_db(song.artist)Example of new non-recoverable
def add_song_to_db(song):
if song.name is None:
raise ValueError('Song must have a name')Example of bubbled-up non-recoverable error
def get_new_song():
song = get_song_from_user()
add_song_to_db(song)Why is it ok to let errors bubble-up?
Separation of concerns. Let higher layers with more context decide how to handle errors. You may not even want to print as it’s not the layers job to concern itself with how output should be handled.