Add tryClose() utility method