Your files never leave your device
Advertisement

Error Handling

Sometimes code fails. Network requests fail, data is malformed. Try/catch prevents these errors from crashing your app.

Try / Catch

Wrap risky code in try. If it throws an error, the catch block runs.

Try It Yourself

        

Throwing Errors

You can create your own errors if invalid data is provided to a function.

Try It Yourself

        

Practice

Challenge 1: Write a function that parses JSON string, wrap JSON.parse in try/catch to handle bad JSON gracefully.

Related Guides

Sponsored Utility
While You're Here
Sponsored Recommendations
Advertisement