adding error handling through stream context to file handler