trycatch file write