How should I do error handling?

Published: Feb 7, 2021 In my last post I told you not to do generic error handling. The natural next question is then “How should I do error handling?”. That question can be hard to answer, and as always in software development the answer is: “It depends”. First of all error handling in every language is different, and you should certainly do what is idiomatic in your specific programming language. ...

February 7, 2021 · Klaus Hebsgaard

How should I do error handling?

How should I do error handling? Published: Feb 7, 2021 Source: https://khebbie.dk/how-should-i-do-error-handling/ In my last post I told you not to do generic error handling. The natural next question is then “How should I do error handling?”. That question can be hard to answer, and as always in software development the answer is: “It depends”. First of all error handling in every language is different, and you should certainly do what is idiomatic in your specific programming language. ...

February 7, 2021 · Klaus Hebsgaard

Don't do generic error handling

Published: Feb 6, 2021 So I just had a look at a fairly new restful api, written in kotlin. 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. The error handling exists in ControllerExceptionHandler.kt The code would look something like: @ExceptionHandler(WebClientResponseException::class) fun handleWebClientResponseException(e: WebClientResponseException): ResponseEntity<Any> { logger().error("Error from WebClient - Status {}: {}", e.rawStatusCode, e.statusText, e) return ResponseEntity(mapOf("error" to "Error in external service"), HttpStatus.BAD_GATEWAY) } That really seems like a smart thing to do - right! ...

February 6, 2021 · Klaus Hebsgaard

Don't do generic error handling

Don’t do generic error handling Published: Feb 6, 2021 Source: https://khebbie.dk/dont-do-generic-error-handling/ So I just had a look at a fairly new restful api, written in kotlin. 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. The error handling exists in ControllerExceptionHandler.kt The code would look something like: @ExceptionHandler(WebClientResponseException::class) fun handleWebClientResponseException(e: WebClientResponseException): ResponseEntity<Any> { logger().error("Error from WebClient - Status {}: {}", e.rawStatusCode, e.statusText, e) return ResponseEntity(mapOf("error" to "Error in external service"), HttpStatus.BAD_GATEWAY) } That really seems like a smart thing to do - right! ...

February 6, 2021 · Klaus Hebsgaard

Exception handling for junior devs

Published: Sep 5, 2017 Exception handling is a very important thing for creating production ready code. When you are a brand new developer you might not know how to do exception handling properly. Here I will try to describe a few basic rules that should be followed when coding. Please note that as always there might be reasons for breaking these rules, but they are a sane default. ...

September 5, 2017 · Klaus Hebsgaard

Exception handling for junior devs

Exception handling for junior devs Published: Sep 5, 2017 Source: https://khebbie.dk/exception-handling-for-junior-devs/ Exception handling is a very important thing for creating production ready code. When you are a brand new developer you might not know how to do exception handling properly. Here I will try to describe a few basic rules that should be followed when coding. Please note that as always there might be reasons for breaking these rules, but they are a sane default. ...

September 5, 2017 · Klaus Hebsgaard

Asserts, Exceptions (and Validation)

Published: Sep 6, 2008 This blog post was originally created at 2008-09-06 At work we have had a bit of a discussion about Debug.Assert and Exceptions. With a little help from google and Steve McConnell’s great book Code Complete we have come to the following definitions: 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. ...

September 6, 2008 · Klaus Hebsgaard

Asserts, Exceptions (and Validation)

Asserts, Exceptions (and Validation) Published: Sep 6, 2008 Source: https://khebbie.dk/asserts-exceptions-and-validation/ This blog post was originally created at 2008-09-06 At work we have had a bit of a discussion about Debug.Assert and Exceptions. With a little help from google and Steve McConnell’s great book Code Complete we have come to the following definitions: 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. ...

September 6, 2008 · Klaus Hebsgaard