trapping exception properly