Evaluate expression: render InvocationExceptions correctly

This commit is contained in:
Natalia Ukhorskaya
2014-12-24 10:47:24 +03:00
parent b6095eca58
commit 94466da61b
2 changed files with 13 additions and 5 deletions
@@ -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)
}
@@ -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
}