Uncaught throw terminates script silently?



  • the following line:

    throw "arbitrary string"; // or throw 2; or throw true;

    if uncaught, terminates my script but does not show up in the console with any "Uncaught blah blah blah" or any kind of error. No error notifications or anything. It just silently terminates the script.

     

    if i change it to:

    throw new Error("arbitrary string");

    it will then show up in the console and i will receive error notifications, but shouldn't the first method be valid as well? Using the MDN page on "throw" as a reference made me think it should. 

    Is this a bug in the game? or am I just misunderstanding something?

    EDIT: just as a side note, i am fairly certain the first method used to work, and now it doesnt, but i could be remembering incorrectly.



  • You can throw whatever you want. That doesn't mean the try{} that implicitly surrounds your code has to catch it gracefully.



  • It is generally accepted that you throw Errors; the cost of instantiating an Error is far less impactful than that of triggering the exception mechanism, so it is in your best interest to do so.

    Also, http://www.devthought.com/2011/12/22/a-string-is-not-an-error/.