A few months ago, I was putting together an internal

Arpit Bhayani

Arpit Bhayani

May 28, 2025 • 1 min read


A few months ago, I was putting together an internal doc exploring different ways to handle errors and exceptions. Here are six common approaches that I could think of

  1. throw a general exception with a detailed error message
  2. return a special value, like null, suggesting an error
  3. return integer codes - 0 for success and non-zero for errors
  4. pass error obj as an arg and let the calling function populate it
  5. monads with optional states for different error types
  6. returning the error object as the return value of the function

There is no one way or a one-size-fits-all approach. The best choice depends on language, team practice, and preferences. But knowing the options does help in picking an elegant one suited for your use case.

Hope it helps.

btw, enrollments open for sys design June cohort - arpitbhayani.me/course

Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses