From dfd3aac900b98628499087afd4ee87ec482d55ab Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Wed, 13 Jun 2012 20:00:54 +0400 Subject: [PATCH] ExceptionUtils.closeQuietly --- .../cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java | 8 ++------ .../src/org/jetbrains/jet/utils/ExceptionUtils.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java index 75a9ba85430..e13d797910e 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java @@ -122,9 +122,7 @@ public class KotlinToJVMBytecodeCompiler { throw ExceptionUtils.rethrow(e); } finally { - try { - outputStream.close(); - } catch (Throwable e) {} + ExceptionUtils.closeQuietly(outputStream); } } } @@ -177,9 +175,7 @@ public class KotlinToJVMBytecodeCompiler { throw ExceptionUtils.rethrow(e); } finally { - try { - os.close(); - } catch (Throwable e) {} + ExceptionUtils.closeQuietly(os); } } else if (outputDir != null) { diff --git a/compiler/util/src/org/jetbrains/jet/utils/ExceptionUtils.java b/compiler/util/src/org/jetbrains/jet/utils/ExceptionUtils.java index 0ea161343e0..de8b7ac2b43 100644 --- a/compiler/util/src/org/jetbrains/jet/utils/ExceptionUtils.java +++ b/compiler/util/src/org/jetbrains/jet/utils/ExceptionUtils.java @@ -16,6 +16,8 @@ package org.jetbrains.jet.utils; +import java.io.Closeable; + /** * @author Stepan Koltsov */ @@ -36,4 +38,13 @@ public class ExceptionUtils { } } + public static void closeQuietly(Closeable closeable) { + if (closeable != null) { + try { + closeable.close(); + } catch (Throwable e) { + } + } + } + }