diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java index ccf13b4a7..6008d04b8 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java @@ -1483,7 +1483,7 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor { } if (!defaultHandlerOccurred) { writer.ws().append("else").ws().append("{").indent().softNewLine(); - writer.append("throw $$je;").softNewLine(); + writer.append("throw $$e;").softNewLine(); writer.outdent().append("}").softNewLine(); } else { writer.softNewLine(); diff --git a/tests/src/test/java/org/teavm/vm/VMTest.java b/tests/src/test/java/org/teavm/vm/VMTest.java index c3f698587..e1677500b 100644 --- a/tests/src/test/java/org/teavm/vm/VMTest.java +++ b/tests/src/test/java/org/teavm/vm/VMTest.java @@ -18,6 +18,7 @@ package org.teavm.vm; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.function.Supplier; import org.junit.Test; @@ -488,4 +489,21 @@ public class VMTest { interface ScriptExecutionWrapper { Object wrap(Supplier execution); } + + @Test + public void uncaughtExceptionRethrown() { + boolean exceptionCaught = false; + try { + try { + throw new NullPointerException("ok"); + } catch (IndexOutOfBoundsException e) { + fail("Should not get there"); + } + fail("Should not get there"); + } catch (NullPointerException e) { + assertEquals("ok", e.getMessage()); + exceptionCaught = true; + } + assertTrue("Exception was not caught", exceptionCaught); + } } \ No newline at end of file