Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pablomarx opened this issue Oct 27, 2018 · 5 comments
Open

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

pablomarx opened this issue Oct 27, 2018 · 5 comments

Comments

@pablomarx
Copy link

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 > 
pguyot added a commit to pguyot/NEWT0 that referenced this issue Jul 9, 2020
Exceptions are now propagated through saved vm environments (gnue#8).
Pop-handler and pop are generated in the right sequence, following NewtonOS
compiler.
Fix si_set_lex_scope for native functions.
Add unit tests for various cases.
Add BinEqual function for tests.
pguyot added a commit to pguyot/NEWT0 that referenced this issue Jul 9, 2020
Exceptions are now propagated through saved vm environments (gnue#8).
Pop-handler and pop are generated in the right sequence, following NewtonOS
compiler.
Fix si_set_lex_scope for native functions.
Add unit tests for various cases.
Add BinEqual function for tests.
pguyot added a commit to pguyot/NEWT0 that referenced this issue Jul 9, 2020
Exceptions are now propagated through saved vm environments (gnue#8).
Pop-handler and pop are generated in the right sequence, following NewtonOS
compiler.
Fix si_set_lex_scope for native functions.
Add unit tests for various cases.
Add BinEqual function for tests.
gnue added a commit that referenced this issue Jul 10, 2020
Fix several issues related to exceptions, including #7 and #8
@morgant
Copy link
Contributor

morgant commented Jul 10, 2020

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

@pguyot
Copy link
Contributor

pguyot commented Jul 11, 2020

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
Copy link
Contributor

morgant commented Jul 11, 2020

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
Copy link
Contributor

pguyot commented Jul 12, 2020

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
Copy link
Contributor

morgant commented Jul 12, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants