errorhandling for close()