smart error catch