{"id":2292,"date":"2022-08-30T15:23:39","date_gmt":"2022-08-30T15:23:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/what-is-the-purpose-of-using-try-catch-blocks-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:23:39","modified_gmt":"2022-08-30T15:23:39","slug":"what-is-the-purpose-of-using-try-catch-blocks-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/what-is-the-purpose-of-using-try-catch-blocks-collection-of-common-programming-errors\/","title":{"rendered":"What is the purpose of using try, catch blocks?-Collection of common programming errors"},"content":{"rendered":"<p>No, it is not a replacement for an if, then block, it serves an entirely different purpose. The objective of a try, catch block is to try and do something which could fail and raise an exception (e.g., read a file from disk, but the file might not be there, etc.). After catching an exception, you can handle it.<\/p>\n<pre><code>try {\n   riskyOperation();\ncatch (ExpectedException) {\n   handleException();\n}\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2014-01-05 09:54:38. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>No, it is not a replacement for an if, then block, it serves an entirely different purpose. The objective of a try, catch block is to try and do something which could fail and raise an exception (e.g., read a file from disk, but the file might not be there, etc.). After catching an exception, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2292","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2292"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2292\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}