From 35ee63feb37dcc38483a35e11fff3f16bb0bfe75 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Tue, 8 Jul 2014 08:39:49 -0700 Subject: Add closeQuietly utility method (1/2) Bug: 6948882 Change-Id: I8960f457ee71bc99da0a88692e55887c8a4df2b4 --- src/com/android/dialer/util/DialerUtils.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/com/android/dialer/util/DialerUtils.java b/src/com/android/dialer/util/DialerUtils.java index f1dfe20e0..484e97d92 100644 --- a/src/com/android/dialer/util/DialerUtils.java +++ b/src/com/android/dialer/util/DialerUtils.java @@ -107,4 +107,21 @@ public class DialerUtils { (TextView) emptyListView.findViewById(R.id.emptyListViewMessage); emptyListViewMessage.setText(res.getString(strResId)); } + + /** + * Closes an {@link AutoCloseable}, silently ignoring any checked exceptions. Does nothing if + * null. + * + * @param closeable to close. + */ + public static void closeQuietly(AutoCloseable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (RuntimeException rethrown) { + throw rethrown; + } catch (Exception ignored) { + } + } + } } -- cgit v1.2.3