Erandid JavaScripti asünkroonses koodis
Asünkroonses koodis tekkivat erandit
ei saa püüda
läbi try-catch:
try {
setTimeout(function() {
throw(new Error); // erandit ei püüta
}, 3000);
} catch(error) {
console.log(error);
}
Selgitage, milles on järgmise koodiga probleem:
try {
elem.addEventListener('click', function() {
JSON.parse('some string');
});
} catch() {
console.log('vigane json');
}