add try catch and flash messages

[re #homework1]