How to Create Taboo Error Handler for Golang

How to Create Taboo Error Handler for Golang

I created this module for Golang to help me with error handling. This idea showed when a colleague of mine was thinking to pass context from handler to service, to repository to trace the error log more verbose. I disagreed with him because I thought that's not what context is for. Perhaps I was wrong or he was wrong, or maybe both of us wrong because this is our first Golang project that deployed on production. In this tutorial, you'll see How to Create Taboo Error Handler for Golang. This post contains my own experience in creating try-catch-like error handler for golang.

I created this module for Golang to help me with error handling. This idea showed when a colleague of mine was thinking to pass context from handler to service, to repository to trace the error log more verbose. I disagreed with him because I thought that's not what context is for. Perhaps I was wrong or he was wrong, or maybe both of us wrong because this is our first Golang project that deployed on production.

Despite our opinion about context, we both agreed that Golang's error handling is too verbose and bulky. It makes us read more error handling more than read the system flow itself. Then I remember when I was coding using Java/Kotlin that I always use throwsthrow, and try-catch block to handle any errors.

Why don’t I create it for Golang?

Then I create this try-catch block module for Golang called taboo. Because I know this thing creates polemic among Golang developer but, then I thought why don't I give it a try?

For the design itself, I was inspired by  this article but the whole implementation is all adjusted with my current needs. Instead of error, this module is based on panic and recover so it is quite dangerous whenever used in the wrong condition.

Let’s take an example:

package main

func div(a, b int) int {
  return a / b
}
func main() {
  div(10, 0)
}

golang error-handling open-source development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

An Open-Source Book About the Open Source World

Open source today is a word that often include a lot of things, such as open knowledge (Wikimedia projects), open hardware (Arduino, Raspberry Pi), open formats (ODT/ODS/ODP) and so on.

Golang Web Development:Th Best Programming Language in 2020

Golang Web Development is the new trend globally. Get all the details about the Golang development here. Hire Golang Developers.

Infographic: Open Source Web Application Development in Enterprises

The open-source software allows anyone to use. This infographic highlights various benefits of open source web application development for large enterprises

Infographic: Open Source Web Application Development in Enterprises

The open-source software allows anyone to use. This infographic highlights various benefits of open source web application development for large enterprises

Developer Career Path: To Become a Team Lead or Stay a Developer?

For a developer, becoming a team leader can be a trap or open up opportunities for creating software. Two years ago, when I was a developer, ... by Oleg Sklyarov, Fullstack Developer at Skyeng company