lou's logo
Published on

error handling in python

Authors
  • avatar
    Name
    Louai Misto
    Twitter

Table of Contents

  1. introduction

introduction

error handling sucks in python.

a common paradigm in languages like go is that functions always return two values. one of those values is an error.

for example:

err, name := getUserName(userId)

if err =! nil {
   fmt.PrintLn("something is messed up")
}

// do something with `name` here

Other languages like Rust use the Result Monad. I'm not really sure if it's a Monad per se, it sure looks like one though. The result might be either a value or an error.

Python and Javascript don't have such facilities. So, to get around this, we'll do what every great dev does and install a third party library.

In the python world, this function