[OpenLayers-Users] suggest adding try/catch around JSON.parse

Eric Lemoine eric.lemoine at camptocamp.com
Mon Feb 13 14:08:10 EST 2012


On Tuesday, December 6, 2011, Charlton Galvarino <charlton at 2creek.com>
wrote:
> In OpenLayers/Format/JSON.js, it would be helpful to have another
try/catch block.  Sometimes my incoming JSON is bad, and as the code stands
now, it throws a .js error and fails.
>
> Original:
>
>    read: function(json, filter) {
>        var object;
>        if (this.nativeJSON) {
>            object = JSON.parse(json, filter);
>        } else try {
>            /**
>             * Parsing happens in three stages. In the first stage, we run
the
>
> Suggested change:
>
>    read: function(json, filter) {
>        var object;
>        if (this.nativeJSON) {
>            try {
>               object = JSON.parse(json, filter);
>            }
>             catch(e) {
>                 // Fall through if the parse fails.
>             }
>        } else try {
>            /**
>             * Parsing happens in three stages. In the first stage, we run
the

Hi. OpenLayers devs much better prefer pull requests than diffs in mails.
Thx :-)

-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120213/118b1f16/attachment.html


More information about the Users mailing list