
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Proper Way to Catch Exception from JSON Parse
The best way to catch invalid JSON parsing errors is to put the calls to JSON.parse() to a try/catch block.
Example
function parseJSONSafely(str) { try { return JSON.parse(str); } catch (e) { console.err(e); // Return a default object, or null based on use case. return {} } }
Advertisements