<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Error-Handling on Klaus Hebsgaard</title><link>https://khebbie.dk/tags/error-handling/</link><description>Recent content in Error-Handling on Klaus Hebsgaard</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sun, 07 Feb 2021 00:00:00 +0000</lastBuildDate><atom:link href="https://khebbie.dk/tags/error-handling/index.xml" rel="self" type="application/rss+xml"/><item><title>How should I do error handling?</title><link>https://khebbie.dk/posts/how-should-i-do-error-handling/</link><pubDate>Sun, 07 Feb 2021 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/how-should-i-do-error-handling/</guid><description>&lt;hr&gt;
&lt;img src="https://images.unsplash.com/photo-1551836022-deb4988cc6c0?auto=format&amp;fit=crop&amp;w=1600&amp;q=80" alt="Flowchart for error handling decisions" width="1600" height="1067" loading="lazy"&gt;
&lt;p&gt;&lt;em&gt;Published: Feb 7, 2021&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;In &lt;a href="https://khebbie.dk/dont-do-generic-error-handling/"&gt;my last post&lt;/a&gt; I told you not to do generic error handling.&lt;/p&gt;
&lt;p&gt;The natural next question is then &amp;ldquo;How should I do error handling?&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;That question can be hard to answer, and as always in software development the answer is: &amp;ldquo;It depends&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;First of all error handling in every language is different, and you should certainly do what is idiomatic in your specific programming language.&lt;/p&gt;</description></item><item><title>How should I do error handling?</title><link>https://khebbie.dk/posts-pages/how-should-i-do-error-handling/</link><pubDate>Sun, 07 Feb 2021 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts-pages/how-should-i-do-error-handling/</guid><description>&lt;h1 id="how-should-i-do-error-handling"&gt;How should I do error handling?&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Published: Feb 7, 2021&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Source: &lt;a href="https://khebbie.dk/how-should-i-do-error-handling/"&gt;https://khebbie.dk/how-should-i-do-error-handling/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;In &lt;a href="https://khebbie.dk/dont-do-generic-error-handling/"&gt;my last post&lt;/a&gt; I told you not to do generic error handling.&lt;/p&gt;
&lt;p&gt;The natural next question is then &amp;ldquo;How should I do error handling?&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;That question can be hard to answer, and as always in software development the answer is: &amp;ldquo;It depends&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;First of all error handling in every language is different, and you should certainly do what is idiomatic in your specific programming language.&lt;/p&gt;</description></item><item><title>Don't do generic error handling</title><link>https://khebbie.dk/posts/dont-do-generic-error-handling/</link><pubDate>Sat, 06 Feb 2021 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/dont-do-generic-error-handling/</guid><description>&lt;hr&gt;
&lt;img src="https://images.unsplash.com/photo-1555949963-aa79dcee981c?auto=format&amp;fit=crop&amp;w=1600&amp;q=80" alt="Magnifying glass over code showing bugs" width="1600" height="1067" loading="lazy"&gt;
&lt;p&gt;&lt;em&gt;Published: Feb 6, 2021&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;So I just had a look at a fairly new restful api, written in kotlin.&lt;/p&gt;
&lt;p&gt;The developers who made the api decided to be smart about error handling - instead of doing error handling in every api endpoint - why not just do some generic error handling.&lt;/p&gt;
&lt;p&gt;The error handling exists in ControllerExceptionHandler.kt&lt;/p&gt;
&lt;p&gt;The code would look something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; @ExceptionHandler(WebClientResponseException::class)
fun handleWebClientResponseException(e: WebClientResponseException): ResponseEntity&amp;lt;Any&amp;gt; {
logger().error(&amp;quot;Error from WebClient - Status {}: {}&amp;quot;, e.rawStatusCode, e.statusText, e)
return ResponseEntity(mapOf(&amp;quot;error&amp;quot; to &amp;quot;Error in external service&amp;quot;), HttpStatus.BAD_GATEWAY)
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That really seems like a smart thing to do - right!&lt;/p&gt;</description></item><item><title>Don't do generic error handling</title><link>https://khebbie.dk/posts-pages/dont-do-generic-error-handling/</link><pubDate>Sat, 06 Feb 2021 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts-pages/dont-do-generic-error-handling/</guid><description>&lt;h1 id="dont-do-generic-error-handling"&gt;Don&amp;rsquo;t do generic error handling&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Published: Feb 6, 2021&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Source: &lt;a href="https://khebbie.dk/dont-do-generic-error-handling/"&gt;https://khebbie.dk/dont-do-generic-error-handling/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;So I just had a look at a fairly new restful api, written in kotlin.&lt;/p&gt;
&lt;p&gt;The developers who made the api decided to be smart about error handling - instead of doing error handling in every api endpoint - why not just do some generic error handling.&lt;/p&gt;
&lt;p&gt;The error handling exists in ControllerExceptionHandler.kt&lt;/p&gt;
&lt;p&gt;The code would look something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; @ExceptionHandler(WebClientResponseException::class)
fun handleWebClientResponseException(e: WebClientResponseException): ResponseEntity&amp;lt;Any&amp;gt; {
logger().error(&amp;quot;Error from WebClient - Status {}: {}&amp;quot;, e.rawStatusCode, e.statusText, e)
return ResponseEntity(mapOf(&amp;quot;error&amp;quot; to &amp;quot;Error in external service&amp;quot;), HttpStatus.BAD_GATEWAY)
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That really seems like a smart thing to do - right!&lt;/p&gt;</description></item><item><title>Exception handling for junior devs</title><link>https://khebbie.dk/posts/exception-handling-for-junior-devs/</link><pubDate>Tue, 05 Sep 2017 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/exception-handling-for-junior-devs/</guid><description>&lt;hr&gt;
&lt;img src="https://images.unsplash.com/photo-1516259762381-22954d7d3ad2?auto=format&amp;fit=crop&amp;w=1600&amp;q=80" alt="Junior developer debugging code with mentor" width="1600" height="1067" loading="lazy"&gt;
&lt;p&gt;&lt;em&gt;Published: Sep 5, 2017&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Exception handling is a very important thing for creating production ready code.&lt;br&gt;
When you are a brand new developer you might not know how to do exception handling properly.&lt;br&gt;
Here I will try to describe a few basic rules that should be followed when coding.&lt;br&gt;
Please note that as always there might be reasons for breaking these rules, but they are a sane default.&lt;/p&gt;</description></item><item><title>Exception handling for junior devs</title><link>https://khebbie.dk/posts-pages/exception-handling-for-junior-devs/</link><pubDate>Tue, 05 Sep 2017 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts-pages/exception-handling-for-junior-devs/</guid><description>&lt;h1 id="exception-handling-for-junior-devs"&gt;Exception handling for junior devs&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Published: Sep 5, 2017&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Source: &lt;a href="https://khebbie.dk/exception-handling-for-junior-devs/"&gt;https://khebbie.dk/exception-handling-for-junior-devs/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Exception handling is a very important thing for creating production ready code.&lt;br&gt;
When you are a brand new developer you might not know how to do exception handling properly.&lt;br&gt;
Here I will try to describe a few basic rules that should be followed when coding.&lt;br&gt;
Please note that as always there might be reasons for breaking these rules, but they are a sane default.&lt;/p&gt;</description></item><item><title>Asserts, Exceptions (and Validation)</title><link>https://khebbie.dk/posts/asserts-exceptions-and-validation/</link><pubDate>Sat, 06 Sep 2008 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts/asserts-exceptions-and-validation/</guid><description>&lt;hr&gt;
&lt;img src="https://images.unsplash.com/photo-1555066931-4365d14bab8c?auto=format&amp;fit=crop&amp;w=1600&amp;q=80" alt="Code editor showing validation errors" width="1600" height="1067" loading="lazy"&gt;
&lt;p&gt;&lt;em&gt;Published: Sep 6, 2008&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;This blog post was originally created at 2008-09-06&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;At work we have had a bit of a discussion about Debug.Assert and Exceptions. With a little help from google and Steve McConnell&amp;rsquo;s great book &lt;a href="http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670"&gt;Code Complete&lt;/a&gt; we have come to the following definitions:&lt;/p&gt;
&lt;p&gt;Both Assertions and Exceptions has to do with technical stuff. Business stuff should be handled by validation logic. Business logic should never appear in assertions and exceptions.&lt;/p&gt;</description></item><item><title>Asserts, Exceptions (and Validation)</title><link>https://khebbie.dk/posts-pages/asserts-exceptions-and-validation/</link><pubDate>Sat, 06 Sep 2008 00:00:00 +0000</pubDate><guid>https://khebbie.dk/posts-pages/asserts-exceptions-and-validation/</guid><description>&lt;h1 id="asserts-exceptions-and-validation"&gt;Asserts, Exceptions (and Validation)&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;Published: Sep 6, 2008&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Source: &lt;a href="https://khebbie.dk/asserts-exceptions-and-validation/"&gt;https://khebbie.dk/asserts-exceptions-and-validation/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;This blog post was originally created at 2008-09-06&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;At work we have had a bit of a discussion about Debug.Assert and Exceptions. With a little help from google and Steve McConnell&amp;rsquo;s great book &lt;a href="http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670"&gt;Code Complete&lt;/a&gt; we have come to the following definitions:&lt;/p&gt;
&lt;p&gt;Both Assertions and Exceptions has to do with technical stuff. Business stuff should be handled by validation logic. Business logic should never appear in assertions and exceptions.&lt;/p&gt;</description></item></channel></rss>