try...catch
Në shqip përdoret i njëjti emër.
ShpjegimiSQ
try...catch e kap një gabim në JavaScript që programi të mos rrëzohet: kodi i rrezikshëm futet te try, dhe nëse diçka shkon keq, ekzekutohet catch. Me throw mund ta krijosh vetë një gabim.
EnglishEN
try...catch catches an error in JavaScript so the program doesn't crash: risky code goes in try, and if something goes wrong, catch runs. With throw you can raise an error yourself.
Si ta mendosh
Si portieri pas mbrojtjes: nëse topi i kalon mbrojtësit (try), portieri është aty ta kapë (catch).
Lexoje në anglisht
Like the goalkeeper behind the defence: if the ball gets past the defenders (try), the keeper is there to catch it (catch).
Shembull kodijavascript
try {
const teDhenat = JSON.parse("{gabim");
} catch (e) {
console.log("JSON i pavlefshëm:", e.message);
}