{"id":1332,"date":"2021-12-21T18:00:29","date_gmt":"2021-12-21T18:00:29","guid":{"rendered":"https:\/\/programmingduck.com\/?p=1332"},"modified":"2021-12-27T19:55:57","modified_gmt":"2021-12-27T19:55:57","slug":"avoiding-exceptions","status":"publish","type":"post","link":"https:\/\/programmingduck.com\/articles\/avoiding-exceptions","title":{"rendered":"How to use error values in an exception-based language"},"content":{"rendered":"<p>As seen in other <a href=\"\/articles\/errors\">error handling<\/a> articles, particularly in <a href=\"\/articles\/exceptions-error-values\">exceptions vs error values<\/a>, you can do error handling with exceptions or error values.<\/p>\n<p>If you&#8217;re using error values, you probably want to avoid exceptions. However, you may be using other code which throws exceptions.<\/p>\n<p>In this case, <a href=\"https:\/\/www.joelonsoftware.com\/2003\/10\/13\/13\/\">do what Joel does to avoid exceptions<\/a>:<\/p>\n<ul>\n<li>don&#8217;t throw your own exceptions<\/li>\n<li>catch and handle every possible exception immediately<\/li>\n<\/ul>\n<h2>Credits<\/h2>\n<ul>\n<li>Robot &#8211; Photo by Aman Pal on Unsplash<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re using error values, you probably want to avoid exceptions. But, how do you do that if you&#8217;re using an exception-based language?<\/p>\n","protected":false},"author":2,"featured_media":1334,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1332","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-clean-code"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v17.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to use error values in an exception-based language - Programming Duck<\/title>\n<meta name=\"description\" content=\"If you&#039;re using error values, you probably want to avoid exceptions. But, how do you do that if you&#039;re using an exception-based language?\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/programmingduck.com\/articles\/avoiding-exceptions\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use error values in an exception-based language - Programming Duck\" \/>\n<meta property=\"og:description\" content=\"If you&#039;re using error values, you probably want to avoid exceptions. But, how do you do that if you&#039;re using an exception-based language?\" \/>\n<meta property=\"og:url\" content=\"https:\/\/programmingduck.com\/articles\/avoiding-exceptions\" \/>\n<meta property=\"og:site_name\" content=\"Programming Duck\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-21T18:00:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-27T19:55:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/programmingduck.com\/wp-content\/uploads\/2021\/12\/aman-pal-TzvMJ6G0ink-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"3072\" \/>\n\t<meta property=\"og:image:height\" content=\"2048\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Spyros Argalias\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/programmingduck.com\/#website\",\"url\":\"https:\/\/programmingduck.com\/\",\"name\":\"Programming Duck\",\"description\":\"Improve your programming\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/programmingduck.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/programmingduck.com\/articles\/avoiding-exceptions#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/programmingduck.com\/wp-content\/uploads\/2021\/12\/aman-pal-TzvMJ6G0ink-unsplash.jpg\",\"contentUrl\":\"https:\/\/programmingduck.com\/wp-content\/uploads\/2021\/12\/aman-pal-TzvMJ6G0ink-unsplash.jpg\",\"width\":3072,\"height\":2048},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/programmingduck.com\/articles\/avoiding-exceptions#webpage\",\"url\":\"https:\/\/programmingduck.com\/articles\/avoiding-exceptions\",\"name\":\"How to use error values in an exception-based language - Programming Duck\",\"isPartOf\":{\"@id\":\"https:\/\/programmingduck.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/programmingduck.com\/articles\/avoiding-exceptions#primaryimage\"},\"datePublished\":\"2021-12-21T18:00:29+00:00\",\"dateModified\":\"2021-12-27T19:55:57+00:00\",\"author\":{\"@id\":\"https:\/\/programmingduck.com\/#\/schema\/person\/46730127720765af154214808615385e\"},\"description\":\"If you're using error values, you probably want to avoid exceptions. But, how do you do that if you're using an exception-based language?\",\"breadcrumb\":{\"@id\":\"https:\/\/programmingduck.com\/articles\/avoiding-exceptions#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/programmingduck.com\/articles\/avoiding-exceptions\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/programmingduck.com\/articles\/avoiding-exceptions#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/programmingduck.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to use error values in an exception-based language\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/programmingduck.com\/#\/schema\/person\/46730127720765af154214808615385e\",\"name\":\"Spyros Argalias\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/programmingduck.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/904c6e2d22d34978942ee1e996d09b66bc47aeb65473b10fc6bb1e16f0237d7d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/904c6e2d22d34978942ee1e996d09b66bc47aeb65473b10fc6bb1e16f0237d7d?s=96&d=mm&r=g\",\"caption\":\"Spyros Argalias\"},\"url\":\"https:\/\/programmingduck.com\/articles\/author\/sargalias\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to use error values in an exception-based language - Programming Duck","description":"If you're using error values, you probably want to avoid exceptions. But, how do you do that if you're using an exception-based language?","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/programmingduck.com\/articles\/avoiding-exceptions","og_locale":"en_US","og_type":"article","og_title":"How to use error values in an exception-based language - Programming Duck","og_description":"If you're using error values, you probably want to avoid exceptions. But, how do you do that if you're using an exception-based language?","og_url":"https:\/\/programmingduck.com\/articles\/avoiding-exceptions","og_site_name":"Programming Duck","article_published_time":"2021-12-21T18:00:29+00:00","article_modified_time":"2021-12-27T19:55:57+00:00","og_image":[{"width":3072,"height":2048,"url":"https:\/\/programmingduck.com\/wp-content\/uploads\/2021\/12\/aman-pal-TzvMJ6G0ink-unsplash.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"Spyros Argalias"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/programmingduck.com\/#website","url":"https:\/\/programmingduck.com\/","name":"Programming Duck","description":"Improve your programming","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/programmingduck.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/programmingduck.com\/articles\/avoiding-exceptions#primaryimage","inLanguage":"en-US","url":"https:\/\/programmingduck.com\/wp-content\/uploads\/2021\/12\/aman-pal-TzvMJ6G0ink-unsplash.jpg","contentUrl":"https:\/\/programmingduck.com\/wp-content\/uploads\/2021\/12\/aman-pal-TzvMJ6G0ink-unsplash.jpg","width":3072,"height":2048},{"@type":"WebPage","@id":"https:\/\/programmingduck.com\/articles\/avoiding-exceptions#webpage","url":"https:\/\/programmingduck.com\/articles\/avoiding-exceptions","name":"How to use error values in an exception-based language - Programming Duck","isPartOf":{"@id":"https:\/\/programmingduck.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/programmingduck.com\/articles\/avoiding-exceptions#primaryimage"},"datePublished":"2021-12-21T18:00:29+00:00","dateModified":"2021-12-27T19:55:57+00:00","author":{"@id":"https:\/\/programmingduck.com\/#\/schema\/person\/46730127720765af154214808615385e"},"description":"If you're using error values, you probably want to avoid exceptions. But, how do you do that if you're using an exception-based language?","breadcrumb":{"@id":"https:\/\/programmingduck.com\/articles\/avoiding-exceptions#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/programmingduck.com\/articles\/avoiding-exceptions"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/programmingduck.com\/articles\/avoiding-exceptions#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/programmingduck.com\/"},{"@type":"ListItem","position":2,"name":"How to use error values in an exception-based language"}]},{"@type":"Person","@id":"https:\/\/programmingduck.com\/#\/schema\/person\/46730127720765af154214808615385e","name":"Spyros Argalias","image":{"@type":"ImageObject","@id":"https:\/\/programmingduck.com\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/904c6e2d22d34978942ee1e996d09b66bc47aeb65473b10fc6bb1e16f0237d7d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/904c6e2d22d34978942ee1e996d09b66bc47aeb65473b10fc6bb1e16f0237d7d?s=96&d=mm&r=g","caption":"Spyros Argalias"},"url":"https:\/\/programmingduck.com\/articles\/author\/sargalias"}]}},"_links":{"self":[{"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/posts\/1332","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/comments?post=1332"}],"version-history":[{"count":2,"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/posts\/1332\/revisions"}],"predecessor-version":[{"id":1336,"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/posts\/1332\/revisions\/1336"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/media\/1334"}],"wp:attachment":[{"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/media?parent=1332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/categories?post=1332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/programmingduck.com\/wp-json\/wp\/v2\/tags?post=1332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}