added non-crashing error handler for file write/read