added exception handling for errors