added try-catch to print error message