[{"data":1,"prerenderedAt":335},["ShallowReactive",2],{"term-e\u002Fexception":3,"related-e\u002Fexception":318},{"id":4,"title":5,"acronym":6,"body":7,"category":299,"description":300,"difficulty":301,"extension":302,"letter":303,"meta":304,"navigation":157,"path":305,"related":306,"seo":312,"sitemap":313,"stem":316,"subcategory":6,"__hash__":317},"terms\u002Fterms\u002Fe\u002Fexception.md","Exception",null,{"type":8,"value":9,"toc":293},"minimark",[10,15,19,23,26,30,282,286,289],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 — The Vibe Check",[16,17,18],"p",{},"An exception is a special kind of error that 'throws' itself up through your code like a hot potato, looking for someone to catch it. If nobody catches it, the whole program crashes. You catch exceptions with try\u002Fcatch blocks and handle them gracefully instead of letting the program explode.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"An exception is an event that disrupts normal program flow and is represented as an object containing error information. When code 'throws' an exception, it unwinds the call stack until a matching catch block is found or the program terminates. Exceptions can be built-in (TypeError, ValueError) or custom classes extending the base Error class.",[11,27,29],{"id":28},"show-me-the-code","Show Me The Code",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-javascript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F Throwing and catching an exception:\nfunction divide(a, b) {\n  if (b === 0) throw new Error(\"Cannot divide by zero\");\n  return a \u002F b;\n}\n\ntry {\n  const result = divide(10, 0);\n} catch (error) {\n  console.error(\"Caught:\", error.message);\n} finally {\n  console.log(\"This always runs\");\n}\n","javascript","",[38,39,40,49,80,130,146,152,159,167,194,209,244,254,277],"code",{"__ignoreMap":36},[41,42,45],"span",{"class":43,"line":44},"line",1,[41,46,48],{"class":47},"sHwdD","\u002F\u002F Throwing and catching an exception:\n",[41,50,52,56,60,64,68,71,74,77],{"class":43,"line":51},2,[41,53,55],{"class":54},"spNyl","function",[41,57,59],{"class":58},"s2Zo4"," divide",[41,61,63],{"class":62},"sMK4o","(",[41,65,67],{"class":66},"sHdIc","a",[41,69,70],{"class":62},",",[41,72,73],{"class":66}," b",[41,75,76],{"class":62},")",[41,78,79],{"class":62}," {\n",[41,81,83,87,91,95,98,102,105,108,111,114,116,119,123,125,127],{"class":43,"line":82},3,[41,84,86],{"class":85},"s7zQu","  if",[41,88,90],{"class":89},"swJcz"," (",[41,92,94],{"class":93},"sTEyZ","b",[41,96,97],{"class":62}," ===",[41,99,101],{"class":100},"sbssI"," 0",[41,103,104],{"class":89},") ",[41,106,107],{"class":85},"throw",[41,109,110],{"class":62}," new",[41,112,113],{"class":58}," Error",[41,115,63],{"class":89},[41,117,118],{"class":62},"\"",[41,120,122],{"class":121},"sfazB","Cannot divide by zero",[41,124,118],{"class":62},[41,126,76],{"class":89},[41,128,129],{"class":62},";\n",[41,131,133,136,139,142,144],{"class":43,"line":132},4,[41,134,135],{"class":85},"  return",[41,137,138],{"class":93}," a",[41,140,141],{"class":62}," \u002F",[41,143,73],{"class":93},[41,145,129],{"class":62},[41,147,149],{"class":43,"line":148},5,[41,150,151],{"class":62},"}\n",[41,153,155],{"class":43,"line":154},6,[41,156,158],{"emptyLinePlaceholder":157},true,"\n",[41,160,162,165],{"class":43,"line":161},7,[41,163,164],{"class":85},"try",[41,166,79],{"class":62},[41,168,170,173,176,179,181,183,186,188,190,192],{"class":43,"line":169},8,[41,171,172],{"class":54},"  const",[41,174,175],{"class":93}," result",[41,177,178],{"class":62}," =",[41,180,59],{"class":58},[41,182,63],{"class":89},[41,184,185],{"class":100},"10",[41,187,70],{"class":62},[41,189,101],{"class":100},[41,191,76],{"class":89},[41,193,129],{"class":62},[41,195,197,200,203,206],{"class":43,"line":196},9,[41,198,199],{"class":62},"}",[41,201,202],{"class":85}," catch",[41,204,205],{"class":93}," (error) ",[41,207,208],{"class":62},"{\n",[41,210,212,215,218,221,223,225,228,230,232,235,237,240,242],{"class":43,"line":211},10,[41,213,214],{"class":93},"  console",[41,216,217],{"class":62},".",[41,219,220],{"class":58},"error",[41,222,63],{"class":89},[41,224,118],{"class":62},[41,226,227],{"class":121},"Caught:",[41,229,118],{"class":62},[41,231,70],{"class":62},[41,233,234],{"class":93}," error",[41,236,217],{"class":62},[41,238,239],{"class":93},"message",[41,241,76],{"class":89},[41,243,129],{"class":62},[41,245,247,249,252],{"class":43,"line":246},11,[41,248,199],{"class":62},[41,250,251],{"class":85}," finally",[41,253,79],{"class":62},[41,255,257,259,261,264,266,268,271,273,275],{"class":43,"line":256},12,[41,258,214],{"class":93},[41,260,217],{"class":62},[41,262,263],{"class":58},"log",[41,265,63],{"class":89},[41,267,118],{"class":62},[41,269,270],{"class":121},"This always runs",[41,272,118],{"class":62},[41,274,76],{"class":89},[41,276,129],{"class":62},[41,278,280],{"class":43,"line":279},13,[41,281,151],{"class":62},[11,283,285],{"id":284},"when-youll-hear-this","When You'll Hear This",[16,287,288],{},"\"Throw an exception if the input is invalid.\" \u002F \"The unhandled exception crashed the server.\"",[290,291,292],"style",{},"html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":36,"searchDepth":51,"depth":51,"links":294},[295,296,297,298],{"id":13,"depth":51,"text":14},{"id":21,"depth":51,"text":22},{"id":28,"depth":51,"text":29},{"id":284,"depth":51,"text":285},"general","An exception is a special kind of error that 'throws' itself up through your code like a hot potato, looking for someone to catch it.","intermediate","md","e",{},"\u002Fterms\u002Fe\u002Fexception",[307,308,309,310,311],"Error","Try\u002FCatch","Error Handling","Stack Trace","Runtime Error",{"title":5,"description":300},{"changefreq":314,"priority":315},"weekly",0.7,"terms\u002Fe\u002Fexception","2p2tv2PR1IpG1Gw--bJlPOLDzKoSsygi94MwQfJyz3Y",[319,323,326,329,332],{"title":307,"path":320,"acronym":6,"category":299,"difficulty":321,"description":322},"\u002Fterms\u002Fe\u002Ferror","beginner","An error is when your program says 'I cannot do that' and either stops or complains loudly. It is the computer's way of telling you something went wrong.",{"title":309,"path":324,"acronym":6,"category":299,"difficulty":301,"description":325},"\u002Fterms\u002Fe\u002Ferror-handling","Error handling is the art of planning for things to go wrong and dealing with them gracefully instead of letting everything catch fire.",{"title":311,"path":327,"acronym":6,"category":299,"difficulty":321,"description":328},"\u002Fterms\u002Fr\u002Fruntime-error","A runtime error is one that only shows up when your program is actually running, not before.",{"title":310,"path":330,"acronym":6,"category":299,"difficulty":321,"description":331},"\u002Fterms\u002Fs\u002Fstack-trace","A stack trace is the error report that tells you exactly which functions were called right before your code crashed.",{"title":308,"path":333,"acronym":6,"category":299,"difficulty":321,"description":334},"\u002Fterms\u002Ft\u002Ftry-catch","Try\u002Fcatch is your safety net. You put risky code in the 'try' box, and if it blows up, the 'catch' box catches the explosion and handles it gracefully inst...",1776518278195]