gnue / NEWT0

NewtonScript
http://gnue.github.io/NEWT0
34 stars 13 forks source link

Exception handler is not invoked when using Perform() #8

Open pablomarx opened 5 years ago

pablomarx commented 5 years ago

The following NewtonScript code demonstrates the problem:

x := { test: func() Throw('|evt.ex.msg|, "This is my message") };

print("try x:test()\n");
try x:test() onexception |evt.ex| do Print("Caught" && CurrentException().message && "\n");

print("try Perform 'test\n");
try Perform(x, 'test, []) onexception |evt.ex| do Print("Caught" && CurrentException().message && "\n");

print("Finished!\n");

When ran under NEWT/0, the output is:

try x:test()
Caught  
try Perform 'test
Finished!

Note: No exception was caught during Perform(x, 'test, [])

Under WallyScript/NewtonScript 1.x:

Welcome to WallyScript!

      0 > x := { test: func() Throw('|evt.ex.msg|, "This is my message") };
#44139D1  {test: <CodeBlock, 0 args #4413999>}
      0 > try x:test() onexception |evt.ex| do Print("Caught" && CurrentException().message && "\n");
"Caught This is my message 
"
#2        NIL
      0 > try Perform(x, 'test, []) onexception |evt.ex| do Print("Caught" && CurrentException().message && "\n");

Stack trace:
   0 : #44139D1.test : 4
       Receiver: (vars.x)
   1 : (functions.Perform)
       Receiver: (vars)
   2 : (#4414679) <CodeBlock, 0 args #4414679> : 11
       Receiver: (vars)
"Caught This is my message 
"
#2        NIL
      0 > 
morgant commented 4 years ago

I've tested and this appears to be resolved by @pguyot's latest fixes. Thanks!

pguyot commented 4 years ago

Indeed, this should be closed, and there is a new regression test. I'm sorry I didn't phrase the commit message in a way to get GitHub to close the issue automatically.

morgant commented 4 years ago

The one thing I didn't pay attention to in my initial testing is that CurrentException().message isn't working, but maybe that's a separate issue.

pguyot commented 4 years ago

Didn't realize you wrote a unit test library in 2012. I wrote a quick and dirty imitation to add unit tests to NEWT/0.

@morgant @gnue : What do you think about merging NSUnit into NEWT/0?

Also, did you try running your library in NTK? I'm in the process of getting NEWT/0 to generate code compatible with the Newton (and therefore similar to or equal to what NTK generates), and did run my NEWT/0 tests in NTK. It required few modifications.

Regarding CurrentException().message, the bug was a typo which I fixed in #18

morgant commented 4 years ago

@pguyot Thanks for yet another fix!

I have to admit that NSUnit is pretty rudimentary and doesn't have all that many assertions. I was just using it to learn NewtonScript and was doing so solely with NEWT/0 (it did lead me to add Perform() support to NEWT/0), so never tested with NTK. At the time, I was running into what I thought were issues in my Perform() implementation and didn't realize that it was more about exceptions implementation. Only with your recent fixes do I see that NSUnit is working.

I'm certainly open to merging NSUnit into NEWT/0, if you and @gnue feel it actually makes sense.