Think of a trapeze artist at the circus. The trick might go perfectly... or they might slip. That's why there's a SAFETY NET below! ๐ฅ
try { } โ "Here's the risky trick" โ code that might failthrow โ how a function YELLS "PROBLEM!" and launches an error into the aircatch (error) { } โ the safety net โ catches the error so your program keeps runningerror.message โ the note inside the error that tells you exactly what went wrongfinally { } โ the cleanup crew โ sweeps the floor NO MATTER WHAT โ success or error!Without a net: one error STOPS everything. ๐ With a net: the error is caught, handled, and the factory keeps making candy! ๐ฌ
fetch() in try/catch โ because the internet fails ALL THE TIME. Today you learn how the net actually works. Every real app โ games, YouTube, WhatsApp โ survives crashes because of try/catch.