From c2b3cd79b31a5f3407f448ec3cef43eb2afa6eeb Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 4 Sep 2012 16:54:08 +0400 Subject: [PATCH] Better exception handling in JetPsiChecker. Exceptions are rethrowed only in test mode. In production, error is logged and error annotation is registered. --- .../jet/plugin/highlighter/JetPsiChecker.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 4f338482a61..ef5788f5662 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -23,6 +23,7 @@ import com.intellij.lang.annotation.Annotation; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.lang.annotation.Annotator; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.roots.ProjectFileIndex; @@ -42,6 +43,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade; import org.jetbrains.jet.plugin.quickfix.JetIntentionActionFactory; import org.jetbrains.jet.plugin.quickfix.QuickFixes; +import org.jetbrains.jet.utils.ExceptionUtils; import java.util.Collection; import java.util.List; @@ -54,6 +56,8 @@ public class JetPsiChecker implements Annotator { private static volatile boolean errorReportingEnabled = true; private static boolean namesHighlightingTest; + private static final Logger LOG = Logger.getInstance(JetPsiChecker.class); + public static void setErrorReportingEnabled(boolean value) { errorReportingEnabled = value; } @@ -126,15 +130,13 @@ public class JetPsiChecker implements Annotator { catch (ProcessCanceledException e) { throw e; } - catch (AssertionError e) { + catch (Throwable e) { // For failing tests and to notify about idea internal error in -ea mode holder.createErrorAnnotation(element, e.getClass().getCanonicalName() + ": " + e.getMessage()); - throw e; - } - catch (Throwable e) { - // TODO - holder.createErrorAnnotation(element, e.getClass().getCanonicalName() + ": " + e.getMessage()); - e.printStackTrace(); + LOG.error(e); + if (ApplicationManager.getApplication().isUnitTestMode()) { + throw ExceptionUtils.rethrow(e); + } } } }