diff --git a/kiss/src/kiss/Macros.hx b/kiss/src/kiss/Macros.hx index 6196ea88..271f9796 100644 --- a/kiss/src/kiss/Macros.hx +++ b/kiss/src/kiss/Macros.hx @@ -594,6 +594,14 @@ class Macros { macros["once"] = once.bind("defvar"); macros["oncePerInstance"] = once.bind("defprop"); + // Replace "try" with this in a try-catch statement to let all exceptions throw + // their original call stacks. This is more convenient for debugging than trying to + // comment out the "try" and its catches, and re-balance parens + macros["letThrow"] = (wholeExp:ReaderExp, exps:Array, k:KissState) -> { + wholeExp.checkNumArgs(1, null, "(letThrow [thing] [catches...])"); + exps[0]; + }; + return macros; } diff --git a/kiss/src/test/cases/BasicTestCase.hx b/kiss/src/test/cases/BasicTestCase.hx index 1d385183..02411c92 100644 --- a/kiss/src/test/cases/BasicTestCase.hx +++ b/kiss/src/test/cases/BasicTestCase.hx @@ -293,6 +293,10 @@ class BasicTestCase extends Test { function testVoid() { _testVoid(); } + + function testLetThrow() { + _testLetThrow(); + } } class BasicObject { diff --git a/kiss/src/test/cases/BasicTestCase.kiss b/kiss/src/test/cases/BasicTestCase.kiss index d06ca99a..6cfcf01d 100644 --- a/kiss/src/test/cases/BasicTestCase.kiss +++ b/kiss/src/test/cases/BasicTestCase.kiss @@ -495,4 +495,14 @@ (defun :Void myVoid [] (set voidRan true)) (defun _testVoid [] (myVoid) - (Assert.isTrue voidRan)) \ No newline at end of file + (Assert.isTrue voidRan)) + +(defun _testLetThrow [] + (try + { + (letThrow + (throw "the error we want") + (catch [e] (Assert.fail))) + (Assert.fail)} + (catch [:String e] + (Assert.equals "the error we want" e)))) \ No newline at end of file