# Development with try-catch in JavaScript

After learning the `try-catch` construct, your coding style should change. Now you must wrap all places where an exception may occur in a `try`-block, and write a reaction to this exception in a `catch`-block.

Given the following code:

`let str = 'some string'; localStorage.setItem('key', str); alert('saved successfully!');`

What's wrong with this code? Fix the shortcomings of this code.

Given the following code:

`let json = '[1,2,3,4,5]'; let arr = JSON.parse(json); let sum = 0; for (let elem of arr) { sum += +elem; } alert(sum);`

What's wrong with this code? Fix the shortcomings of this code.

←→
↑
en ru