ExceptionUtils.rethrow

This commit is contained in:
Stepan Koltsov
2012-06-06 23:58:19 +04:00
parent 9da5fe11d9
commit 3408c9833c
4 changed files with 45 additions and 14 deletions
@@ -26,6 +26,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import junit.framework.Test;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.utils.ExceptionUtils;
import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.JetTestUtils;
@@ -138,7 +139,7 @@ public class JetDiagnosticsTest extends JetLiteFixture {
Files.write(content, javaFile, Charset.forName("utf-8"));
hasJavaFiles = true;
} catch (Exception e) {
throw new RuntimeException(e);
throw ExceptionUtils.rethrow(e);
}
}
@@ -16,7 +16,6 @@
package org.jetbrains.jet.codegen;
import com.google.common.base.Objects;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import com.intellij.openapi.util.Pair;
@@ -24,6 +23,7 @@ import com.intellij.psi.PsiFile;
import com.intellij.testFramework.UsefulTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.utils.ExceptionUtils;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
@@ -43,7 +43,6 @@ import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collections;
import java.util.List;
/**
@@ -163,7 +162,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
}
}
catch (Exception e) {
throw new RuntimeException(e);
throw ExceptionUtils.rethrow(e);
}
}
@@ -21,6 +21,7 @@ import gnu.trove.THashSet;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jetbrains.jet.utils.ExceptionUtils;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration;
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
@@ -55,18 +56,14 @@ public class TestlibTest extends CodegenTestCase {
try {
setUp();
return doBuildSuite();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
throw ExceptionUtils.rethrow(e);
}
finally {
try {
tearDown();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
throw ExceptionUtils.rethrow(e);
}
}
}
@@ -155,10 +152,8 @@ public class TestlibTest extends CodegenTestCase {
}
return suite;
} catch (RuntimeException e) {
throw e;
} catch (Throwable e) {
throw new RuntimeException(e);
} catch (Exception e) {
throw ExceptionUtils.rethrow(e);
}
}
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.utils;
/**
* @author Stepan Koltsov
*/
public class ExceptionUtils {
/**
* Translate exception to unchecked exception.
*/
public static RuntimeException rethrow(Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
else {
throw new RuntimeException(e);
}
}
}