Closed githubuser5859 closed 8 years ago
The exception is thrown due to invalid JSON syntax: [1, 2, 3)
. Since you did not wrap your JSON.parse
usage in a try
-catch
block, the exception is not caught and bubbles up, which is the expected behaviour, as per the spec. If JSON 2 does not do so, it is an error on their part.
HTML page:
As you can see from the above sample HTML page, I purposely used an incorrect string to throw an exception. The exception is not getting caught. In fact, the error it produces the following in Microsoft IE7 through IE11:
In Google Chrome, the following error appears and can be visible with the developer toolbar:
Now, my question is this: Is this by design or a bug? I can easily fix this by catching the exception, i.e. wrap the parse method with a try..catch block. But if I'm using a third-party plugin which relies on JSON parsing and it expects the JSON3 library to catch the exception, I may have to wait until the author fixes his/her plugin.
Another workaround, particularly for legacy versions of IE, is to employ the JSON2 library (https://github.com/douglascrockford/JSON-js). I did not experience any errors related to uncaught thrown exceptions with the JSON2 library. I didn't look at the code, but I gather it takes care of catching these exceptions.
So, again, is this uncaught exception by design and it's up to the developer to catch it or is it a bug and JSON3 should take care of catching exceptions?
Thank you very much.