{"id":56524,"date":"2023-01-25T15:03:55","date_gmt":"2023-01-25T09:33:55","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=56524"},"modified":"2024-01-02T17:41:48","modified_gmt":"2024-01-02T12:11:48","slug":"why-and-how-finally-block-is-not-meaningless","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/","title":{"rendered":"Why and how finally{\u2026} block is NOT meaningless"},"content":{"rendered":"<p><img decoding=\"async\" alt=\"Blog image\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/01\/1i__cDHMZ7lr508TD06h-xw.png\" \/><\/p>\n<p>A definition first (from the internet):<\/p>\n<p id=\"63a5\" class=\"pw-post-body-paragraph abs abt abu ql b abv afq vz abx aby afr wc aca acb afs acd ace acf aft ach aci acj afu acl acm acn nd bx\" data-selectable-paragraph=\"\"><code class=\"em agj agk agl aga b\"><strong class=\"ql mx\">try-catch-finally<\/strong><\/code><strong class=\"ql mx\">\u00a0is used to handle runtime errors and prevent them from halting the execution of a program.<\/strong><\/p>\n<p id=\"16e3\" class=\"pw-post-body-paragraph abs abt abu ql b abv afq vz abx aby afr wc aca acb afs acd ace acf aft ach aci acj afu acl acm acn nd bx\" data-selectable-paragraph=\"\">The finally block triggers regardless of:<\/p>\n<ol class=\"\">\n<li id=\"c5b4\" class=\"ahd ahe abu ql b abv afq aby afr acb ahf acf ahg acj ahh acn ahi ahj ahk dz bx\" data-selectable-paragraph=\"\">what is implemented inside the\u00a0<code class=\"em agj agk agl aga b\">try-catch<\/code>\u00a0block<\/li>\n<li id=\"6364\" class=\"ahd ahe abu ql b abv ahl aby ahm acb ahn acf aho acj ahp acn ahi ahj ahk dz bx\" data-selectable-paragraph=\"\">any errors encountered inside\u00a0<code class=\"em agj agk agl aga b\">try-catch<\/code>\u00a0block<\/li>\n<li id=\"3161\" class=\"ahd ahe abu ql b abv ahl aby ahm acb ahn acf aho acj ahp acn ahi ahj ahk dz bx\" data-selectable-paragraph=\"\">any\u00a0<code class=\"em agj agk agl aga b\">return<\/code>\u00a0statement written inside the\u00a0<code class=\"em agj agk agl aga b\">try-catch<\/code>\u00a0block<\/li>\n<\/ol>\n<h4 id=\"773e\" class=\"agn age abu bu wr ago agp agq pp agr ags agt pu pv agu pw pz qa agv qb qe qf agw qg qj agx bx\">Example 1<\/h4>\n<p id=\"6784\" class=\"pw-post-body-paragraph abs abt abu ql b abv agy vz abx aby agz wc aca acb aha acd ace acf ahb ach aci acj ahc acl acm acn nd bx\" data-selectable-paragraph=\"\">Consider this example\u00a0<strong class=\"ql mx\">where there\u2019s no error<\/strong>:<\/p>\n<pre>(<span class=\"hljs-function\">()=&gt;<\/span>{\r\n<span class=\"hljs-keyword\">try<\/span> {\r\n<span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(<span class=\"hljs-string\">`Try block triggered`<\/span>)\r\n<span class=\"hljs-keyword\">return<\/span> \r\n} <span class=\"hljs-keyword\">catch<\/span> (error) {\r\n<span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(error)\r\n}<span class=\"hljs-keyword\">finally<\/span>{\r\n<span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(<span class=\"hljs-string\">'Finally triggered'<\/span>)\r\n}\r\n\r\n<span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(<span class=\"hljs-string\">`Rest of the code outside try-catch`<\/span>)\r\n\r\n})()<\/pre>\n<pre class=\"ui afz aga anh aoj iq nr bx\"><span id=\"ead2\" class=\"aii age abu aga b eb aok aol y aom agi\" data-selectable-paragraph=\"\">\/\/ Output\r\n<\/span><span id=\"bf17\" class=\"aii age abu aga b eb aon aol y aom agi\" data-selectable-paragraph=\"\">Try block triggered\r\n<\/span><span id=\"35e6\" class=\"aii age abu aga b eb aon aol y aom agi\" data-selectable-paragraph=\"\">Finally triggered<\/span><\/pre>\n<blockquote><p><em><strong class=\"ql mx\">Note that the \u201cRest of the code outside try-catch\u201d doesn\u2019t get logged on the console<\/strong><\/em><\/p><\/blockquote>\n<p>The finally block will override the return statement written inside the try block.<\/p>\n<pre>(<span class=\"hljs-function\">()=&gt;<\/span>{\r\n<span class=\"hljs-keyword\">try<\/span> {\r\n\r\n<span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(<span class=\"hljs-string\">`Try block triggered`<\/span>)\r\n\r\n<span class=\"hljs-keyword\">throw<\/span> <span class=\"hljs-string\">`Oops... an error occurred`<\/span> \r\n\r\n} <span class=\"hljs-keyword\">catch<\/span> (error) {\r\n\r\n<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(error)\r\n\r\n} <span class=\"hljs-keyword\">finally<\/span>{\r\n\r\n<span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(<span class=\"hljs-string\">'Finally triggered'<\/span>)\r\n}\r\n\r\n<span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(<span class=\"hljs-string\">`Rest of the code outside try-catch`<\/span>)\r\n})()<\/pre>\n<pre class=\"ui afz aga anh aoj iq nr bx\"><span id=\"b9bc\" class=\"aii age abu aga b eb aok aol y aom agi\" data-selectable-paragraph=\"\">\/\/Output\r\n<\/span><span id=\"2937\" class=\"aii age abu aga b eb aon aol y aom agi\" data-selectable-paragraph=\"\">Try block triggered\r\n<\/span><span id=\"ba0f\" class=\"aii age abu aga b eb aon aol y aom agi\" data-selectable-paragraph=\"\">Oops... an error occurred\r\n<\/span><span id=\"5b3d\" class=\"aii age abu aga b eb aon aol y aom agi\" data-selectable-paragraph=\"\">Finally triggered\r\n<\/span><\/pre>\n<blockquote><p><em><strong class=\"ql mx\">Note that the \u201cRest of the code outside try-catch\u201d doesn\u2019t get logged on the console because of the return statement<\/strong><\/em><\/p><\/blockquote>\n<p>From both the example, it becomes apparent that\u00a0<code class=\"em agj agk agl aga b\">finally<\/code>\u00a0block gets executed while the code written outside the\u00a0<code class=\"em agj agk agl aga b\">try-catch-finally<\/code>\u00a0block doesn\u2019t get executed.<\/p>\n<h4 id=\"7687\" class=\"agn age abu bu wr ago agp agq pp agr ags agt pu pv agu pw pz qa agv qb qe qf agw qg qj agx bx\">Example 3<\/h4>\n<p id=\"4948\" class=\"pw-post-body-paragraph abs abt abu ql b abv agy vz abx aby agz wc aca acb aha acd ace acf ahb ach aci acj ahc acl acm acn nd bx\" data-selectable-paragraph=\"\">Consider this example\u00a0<strong class=\"ql mx\">where there is no<\/strong>\u00a0<code class=\"em agj agk agl aga b\">return<\/code>\u00a0<strong class=\"ql mx\">statement<\/strong>:<\/p>\n<pre class=\"afv afw afx afy adr afz aga eg gm agb agc bx\"><span id=\"f174\" class=\"agd age abu aga b bv agf agg y agh agi\" data-selectable-paragraph=\"\">(<span class=\"hljs-function\">()=&gt;<\/span>{\r\n    <span class=\"hljs-keyword\">try<\/span> {\r\n      \r\n      <span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(<span class=\"hljs-string\">`Try block triggered`<\/span>)\r\n      \r\n      <span class=\"hljs-keyword\">throw<\/span> <span class=\"hljs-string\">`Oops... an error occurred`<\/span>\r\n    \r\n    } <span class=\"hljs-keyword\">catch<\/span> (error) {\r\n    \r\n      <span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(error)\r\n   \r\n     }<span class=\"hljs-keyword\">finally<\/span>{\r\n    \r\n      <span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(<span class=\"hljs-string\">'Finally triggered'<\/span>)\r\n   \r\n     }\r\n    \r\n  <span class=\"hljs-variable.language\">console<\/span>.<span class=\"hljs-title.function\">log<\/span>(<span class=\"hljs-string\">`Rest of the code outside try-catch`<\/span>)\r\n})()<\/span><\/pre>\n<pre class=\"ui afz aga anh aoj iq nr bx\"><span id=\"f243\" class=\"aii age abu aga b eb aok aol y aom agi\" data-selectable-paragraph=\"\">\/\/Output\r\nTry block triggered\r\n<\/span><span id=\"ea18\" class=\"aii age abu aga b eb aon aol y aom agi\" data-selectable-paragraph=\"\">Oops... an error occurred\r\n<\/span><span id=\"4702\" class=\"aii age abu aga b eb aon aol y aom agi\" data-selectable-paragraph=\"\">Finally triggered\r\n<\/span><span id=\"0cfc\" class=\"aii age abu aga b eb aon aol y aom agi\" data-selectable-paragraph=\"\">Rest of the code outside try-catch<\/span><\/pre>\n<blockquote>\n<p data-selectable-paragraph=\"\"><em><strong class=\"ql mx\">Note that this time, \u201cRest of the code outside try-catch\u201d gets printed on the console because there is no return statement in this example implementation<\/strong><\/em><\/p>\n<\/blockquote>\n<p id=\"4421\" class=\"pw-post-body-paragraph abs abt abu ql b abv afq vz abx aby afr wc aca acb afs acd ace acf aft ach aci acj afu acl acm acn nd bx\" data-selectable-paragraph=\"\"><strong class=\"ql mx\">A good use-case for finally block can be to put important codes such as clean up code e.g. closing the file or closing the connection<\/strong>.<\/p>\n<p id=\"50b9\" class=\"pw-post-body-paragraph abs abt abu ql b abv afq vz abx aby afr wc aca acb afs acd ace acf aft ach aci acj afu acl acm acn nd bx\" data-selectable-paragraph=\"\">Hence, we may not necessarily need a finally{\u2026} block in our code all the time, but it can serve an important purpose for certain similar use-cases.<\/p>\n<p data-selectable-paragraph=\"\">***<\/p>\n<h3 id=\"1328\" class=\"agn age abu bu wr ago aix agq pp agr aiy agt pu pv aiz pw pz qa aja qb qe qf ajb qg qj agx bx\">Note of thanks \u2764\ufe0f<\/h3>\n<p><img decoding=\"async\" alt=\"Blog image\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/01\/1L-DG46rgfgciZTXEDmAEbw.gif\" \/><\/p>\n<p>Thank you for stopping by. Hope, you find this article useful. Please <a class=\"ax aht\" href=\"https:\/\/medium.com\/@shiva.chaturvedi91\" rel=\"noopener\"><strong class=\"ql mx\"><em class=\"ahq\">follow me<\/em><\/strong><\/a>\u00a0on medium and help me reach 1k followers ??. That will truly encourage me to put out more content.<\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>A definition first (from the internet): try-catch-finally\u00a0is used to handle runtime errors and prevent them from halting the execution of a program. The finally block triggers regardless of: what is implemented inside the\u00a0try-catch\u00a0block any errors encountered inside\u00a0try-catch\u00a0block any\u00a0return\u00a0statement written inside the\u00a0try-catch\u00a0block Example 1 Consider this example\u00a0where there\u2019s no error: (()=&gt;{ try { console.log(`Try block triggered`) [&hellip;]<\/p>\n","protected":false},"author":1535,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":29,"footnotes":""},"categories":[3429,4684,1185,1994,1],"tags":[5084,5093,1787,229,55,1177,1472],"class_list":["post-56524","post","type-post","status-publish","format-standard","hentry","category-front-end-development","category-mean-2","category-node-js-2","category-software-development","category-technology","tag-backend","tag-computer-science","tag-development","tag-services","tag-javascript","tag-nodejs-2","tag-programming"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"A definition first (from the internet): try-catch-finally is used to handle runtime errors and prevent them from halting the execution of a program. The finally block triggers regardless of: what is implemented inside the try-catch block any errors encountered inside try-catch block any return statement written inside the try-catch block Example 1 Consider this example where there\u2019s no error: (()=&gt;{ try { console.log(`Try block triggered`)\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Shivang Chaturvedi\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Why and how finally{\u2026} block is NOT meaningless | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"A definition first (from the internet): try-catch-finally is used to handle runtime errors and prevent them from halting the execution of a program. The finally block triggers regardless of: what is implemented inside the try-catch block any errors encountered inside try-catch block any return statement written inside the try-catch block Example 1 Consider this example where there\u2019s no error: (()=&gt;{ try { console.log(`Try block triggered`)\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Why and how finally{\u2026} block is NOT meaningless | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"A definition first (from the internet): try-catch-finally is used to handle runtime errors and prevent them from halting the execution of a program. The finally block triggers regardless of: what is implemented inside the try-catch block any errors encountered inside try-catch block any return statement written inside the try-catch block Example 1 Consider this example where there\u2019s no error: (()=&gt;{ try { console.log(`Try block triggered`)\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/#article\",\"name\":\"Why and how finally{\\u2026} block is NOT meaningless | TO THE NEW Blog\",\"headline\":\"Why and how finally{\\u2026} block is NOT meaningless\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shivang-chaturvedi\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"\\\/blog\\\/wp-ttn-blog\\\/uploads\\\/2024\\\/01\\\/1i__cDHMZ7lr508TD06h-xw.png\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/#articleImage\"},\"datePublished\":\"2023-01-25T15:03:55+05:30\",\"dateModified\":\"2024-01-02T17:41:48+05:30\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/#webpage\"},\"articleSection\":\"Front End Development, MEAN, Node.js, Software development, Technology, Backend, Computer Science, Development, grails services, javascript, nodejs, programming\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/#listItem\",\"name\":\"Why and how finally{\\u2026} block is NOT meaningless\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/#listItem\",\"position\":3,\"name\":\"Why and how finally{\\u2026} block is NOT meaningless\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shivang-chaturvedi\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shivang-chaturvedi\\\/\",\"name\":\"Shivang Chaturvedi\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/#authorImage\",\"url\":\"https:\\\/\\\/newersworld-sf-static.tothenew.net\\\/prod\\\/profilePicFolder\\\/781d8391-ed8b-4046-b370-50390c28c0c1_Shivang-Chaturvedi-Profile-Pitcure.jpeg\",\"width\":96,\"height\":96,\"caption\":\"Shivang Chaturvedi\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/\",\"name\":\"Why and how finally{\\u2026} block is NOT meaningless | TO THE NEW Blog\",\"description\":\"A definition first (from the internet): try-catch-finally is used to handle runtime errors and prevent them from halting the execution of a program. The finally block triggers regardless of: what is implemented inside the try-catch block any errors encountered inside try-catch block any return statement written inside the try-catch block Example 1 Consider this example where there\\u2019s no error: (()=>{ try { console.log(`Try block triggered`)\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/why-and-how-finally-block-is-not-meaningless\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shivang-chaturvedi\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shivang-chaturvedi\\\/#author\"},\"datePublished\":\"2023-01-25T15:03:55+05:30\",\"dateModified\":\"2024-01-02T17:41:48+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Why and how finally{\u2026} block is NOT meaningless | TO THE NEW Blog","description":"A definition first (from the internet): try-catch-finally is used to handle runtime errors and prevent them from halting the execution of a program. The finally block triggers regardless of: what is implemented inside the try-catch block any errors encountered inside try-catch block any return statement written inside the try-catch block Example 1 Consider this example where there\u2019s no error: (()=>{ try { console.log(`Try block triggered`)","canonical_url":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/#article","name":"Why and how finally{\u2026} block is NOT meaningless | TO THE NEW Blog","headline":"Why and how finally{\u2026} block is NOT meaningless","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/shivang-chaturvedi\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"\/blog\/wp-ttn-blog\/uploads\/2024\/01\/1i__cDHMZ7lr508TD06h-xw.png","@id":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/#articleImage"},"datePublished":"2023-01-25T15:03:55+05:30","dateModified":"2024-01-02T17:41:48+05:30","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/#webpage"},"articleSection":"Front End Development, MEAN, Node.js, Software development, Technology, Backend, Computer Science, Development, grails services, javascript, nodejs, programming"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/www.tothenew.com\/blog\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/#listItem","name":"Why and how finally{\u2026} block is NOT meaningless"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/#listItem","position":3,"name":"Why and how finally{\u2026} block is NOT meaningless","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/shivang-chaturvedi\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/shivang-chaturvedi\/","name":"Shivang Chaturvedi","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/#authorImage","url":"https:\/\/newersworld-sf-static.tothenew.net\/prod\/profilePicFolder\/781d8391-ed8b-4046-b370-50390c28c0c1_Shivang-Chaturvedi-Profile-Pitcure.jpeg","width":96,"height":96,"caption":"Shivang Chaturvedi"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/","name":"Why and how finally{\u2026} block is NOT meaningless | TO THE NEW Blog","description":"A definition first (from the internet): try-catch-finally is used to handle runtime errors and prevent them from halting the execution of a program. The finally block triggers regardless of: what is implemented inside the try-catch block any errors encountered inside try-catch block any return statement written inside the try-catch block Example 1 Consider this example where there\u2019s no error: (()=>{ try { console.log(`Try block triggered`)","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/shivang-chaturvedi\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/shivang-chaturvedi\/#author"},"datePublished":"2023-01-25T15:03:55+05:30","dateModified":"2024-01-02T17:41:48+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Why and how finally{\u2026} block is NOT meaningless | TO THE NEW Blog","og:description":"A definition first (from the internet): try-catch-finally is used to handle runtime errors and prevent them from halting the execution of a program. The finally block triggers regardless of: what is implemented inside the try-catch block any errors encountered inside try-catch block any return statement written inside the try-catch block Example 1 Consider this example where there\u2019s no error: (()=&gt;{ try { console.log(`Try block triggered`)","og:url":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Why and how finally{\u2026} block is NOT meaningless | TO THE NEW Blog","twitter:description":"A definition first (from the internet): try-catch-finally is used to handle runtime errors and prevent them from halting the execution of a program. The finally block triggers regardless of: what is implemented inside the try-catch block any errors encountered inside try-catch block any return statement written inside the try-catch block Example 1 Consider this example where there\u2019s no error: (()=&gt;{ try { console.log(`Try block triggered`)","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"56524","title":null,"description":null,"keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"#aioseo-article-65e064e4a13ec","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"limit_modified_date":false,"created":"2023-01-25 09:33:37","updated":"2024-02-29 11:05:08","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tWhy and how finally{\u2026} block is NOT meaningless\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Technology","link":"https:\/\/www.tothenew.com\/blog\/category\/technology\/"},{"label":"Why and how finally{\u2026} block is NOT meaningless","link":"https:\/\/www.tothenew.com\/blog\/why-and-how-finally-block-is-not-meaningless\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1535"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=56524"}],"version-history":[{"count":3,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56524\/revisions"}],"predecessor-version":[{"id":59745,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/56524\/revisions\/59745"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=56524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=56524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=56524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}