Handling Errors... or not

This post is mainly about Javascript, but I believe that it is applicable to any language that has exceptions which can be thrown and handled. I will try to keep the examples high-level.

You know that you should handle your exceptions, right. Sometimes you remember to and sometimes you don’t. When you don’t, do you feel a bit guilty that you’re not being a “good” or “professional” programmer? What would it look like if you handled every single exception in your code? It would probably be bloated and hard to maintain. When and why should we handle exceptions?

JS NOTE: I thought at first that catch would get the error but the promise chain would still allow other catch calls. It makes sense that it doesn’t, otherwise you wouldn’t be able to choose to either handle an error or let it bubble.

NOTE: Logging errors depends on the quality of the code doing the logging. If somebody writes: logger.error('call failed') you won’t see the error message to know why. If somebody writes logger.error('service call error: ' + err.message), that is better, but you don’t know which service and you don’t have a stack trace. This is why exception have the ability to “bubble”. It is a standard way to pass all that information up so that it can be logged / sent off / etc… in a standard way. That doesn’t mean you should just let errors happen. Attaching your business logic’s context can be very useful in seeing immediately where an error came from. Ideally you would do that in a standard way to reduce the need to dig through the code to find where the error came from

  • Logging is useful for debugging, but it isn’t in-your-face. We’re not always looking at logs
  • Exception tracking is better. In-your-face. Sends E-Mails/Slack message/etc… Lets you organize your errors

  • Hypothesis:
    • Functions at a “lower level” which handle their errors (and log, or just simply return a fake value) make errors hard to see
    • Need to distinguish between something that you expect to happen and you’re OK with a default value, and something that you don’t expect and really need to know about
    • Lat/long of 0,0 is rarely acceptable. Don’t return 0/empty string/etc… if you don’t know what the value should be

Discuss “Functional Core, Imperative Shell” (?)

  • https://github.com/kbilsted/Functional-core-imperative-shell/blob/master/README.md
  • https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell

Notes:

  • Investigate: https://jamesonzimmer.com/dynamic-footnotes-markdown-jekyll-no-plugin/
  • Look again at Exceptional Ruby
  • Catching errors early means that they can’t be caught and dealt with by higher, more general, logging / exception reporting handlers
  • I wrote some stuff in my notebook
  • Use multiple languages? or just pseudo code?

2021

Why I Love Lodash

I love Lodash, but I’m not here to tell you to use Lodash. It’s up to you to decide if a tool is useful for you or your project. It will come down to the n...

Handling Errors… or not

This post is mainly about Javascript, but I believe that it is applicable to any language that has exceptions which can be thrown and handled. I will try to...

Back to Top ↑

2020

Structuring an Elixir+Phoenix App

I’ve mix phx.new ed many applications and when doing so I often start with wondering how to organize my code. I love how Phoenix pushes you to think about th...

Back to Top ↑

2015

Master Data Management Scoring Examples

A while ago my colleague Michael suggested to me that I draw out some examples of how my record linkage algorithm did it’s thing. In order to do that, I’ve ...

Loading SQL to Neo4j Like Magic

When using neo4j for the first time, most people want to import data from another database to start playing around. There are a lot of options including LOA...

Back to Top ↑

2014

Normalizing Religion in Ireland

When I told the people of Northern Ireland that I was an atheist, a woman in the audience stood up and said, ‘Yes, but is it the God of the Catholics or t...

Back to Top ↑