try catch errors when writing in logs