From 94466da61b02525a3fc9c5ba864e0592d4d329cc Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Wed, 24 Dec 2014 10:47:24 +0300 Subject: [PATCH] Evaluate expression: render InvocationExceptions correctly --- .../debugger/evaluate/KotlinEvaluationBuilder.kt | 14 +++++++++++--- .../src/evaluate/multipleBreakpoints/exceptions.kt | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt index 6045efc16fd..d9db22705b3 100644 --- a/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt +++ b/idea/src/org/jetbrains/jet/plugin/debugger/evaluate/KotlinEvaluationBuilder.kt @@ -77,6 +77,7 @@ import org.jetbrains.jet.plugin.util.attachment.attachmentByPsiFile import com.intellij.openapi.diagnostic.Attachment import org.jetbrains.jet.plugin.util.attachment.mergeAttachments import com.sun.jdi.ClassType +import com.sun.jdi.InvocationException private val RECEIVER_NAME = "\$receiver" private val THIS_NAME = "this" @@ -211,7 +212,14 @@ class KotlinEvaluator(val codeFragment: JetCodeFragment, private fun InterpreterResult.toJdiValue(vm: VirtualMachine): com.sun.jdi.Value? { val jdiValue = when (this) { is ValueReturned -> result - is ExceptionThrown -> exception(exception.toString()) + is ExceptionThrown -> { + if (this.kind == ExceptionThrown.ExceptionKind.FROM_EVALUATED_CODE) { + exception(InvocationException(this.exception.value as ObjectReference)) + } + else { + exception(exception.toString()) + } + } is AbnormalTermination -> exception(message) else -> throw IllegalStateException("Unknown result value produced by eval4j") } @@ -264,10 +272,10 @@ class KotlinEvaluator(val codeFragment: JetCodeFragment, private fun exception(msg: String) = throw EvaluateExceptionUtil.createEvaluateException(msg) - private fun exception(e: Throwable) { + private fun exception(e: Throwable): Nothing { val message = e.getMessage() if (message != null) { - exception(message) + throw EvaluateExceptionUtil.createEvaluateException(message, e) } throw EvaluateExceptionUtil.createEvaluateException(e) } diff --git a/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/exceptions.kt b/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/exceptions.kt index 64275d5f9a8..3db2a8b12e6 100644 --- a/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/exceptions.kt +++ b/idea/testData/debugger/tinyApp/src/evaluate/multipleBreakpoints/exceptions.kt @@ -4,12 +4,12 @@ import java.util.ArrayList fun throwException() { // EXPRESSION: fail() - // RESULT: instance of java.lang.UnsupportedOperationException(id=ID): Ljava/lang/UnsupportedOperationException; + // RESULT: Exception occurred in target VM: Method threw 'java.lang.UnsupportedOperationException' exception. //Breakpoint! val a = 1 // EXPRESSION: fail() - // RESULT: instance of java.lang.UnsupportedOperationException(id=ID): Ljava/lang/UnsupportedOperationException; + // RESULT: Exception occurred in target VM: Method threw 'java.lang.UnsupportedOperationException' exception. //Breakpoint! val b = 1 }