tnativeexc.nim 580 B

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. action: "run"
  3. """
  4. import jsffi
  5. # Can catch JS exceptions
  6. try:
  7. asm """throw new Error('a new error');"""
  8. except JsError as e:
  9. doAssert e.message == "a new error"
  10. except:
  11. doAssert false
  12. # Can distinguish different exceptions
  13. try:
  14. asm """JSON.parse(';;');"""
  15. except JsEvalError:
  16. doAssert false
  17. except JsSyntaxError as se:
  18. doAssert se.message == "Unexpected token ; in JSON at position 0"
  19. except JsError as e:
  20. doAssert false
  21. # Can catch parent exception
  22. try:
  23. asm """throw new SyntaxError();"""
  24. except JsError as e:
  25. discard
  26. except:
  27. doAssert false