catch error and print it with last query