throw-basic.js 333 B

1234567891011121314151617181920212223242526
  1. function assert(x) { if (!x) console.log("FAIL"); }
  2. try {
  3. throw 1;
  4. } catch (e) {
  5. assert(e === 1);
  6. }
  7. try {
  8. throw [99];
  9. } catch (e) {
  10. assert(typeof e === "object");
  11. assert(e.length === 1);
  12. }
  13. function foo() {
  14. throw "hello";
  15. }
  16. try {
  17. foo();
  18. } catch (e) {
  19. assert(e === "hello");
  20. }
  21. console.log("PASS");