DEV Community

Ashraful Islam
Ashraful Islam

Posted on

How to throwing our own errors

Throwing our own errors
What if json is syntactically correct, but doesn’t have a required name property?

Top comments (1)

Collapse
 
_gdelgado profile image
Gio • Edited
const data = JSON.parse(jsonString)

if (!data.requiredName) {
  throw new Error('missing required field')
}
Enter fullscreen mode Exit fullscreen mode