---
title: "Discussion on \"Away from exceptions: errors as values\" | Hashnode"
description: "Discussion on \"Away from exceptions: errors as values\". Programming with exceptions is difficult and inelegant. Learn how to handle errors better by representing them as values."
url: "https://hashnode.com/posts/away-from-exceptions-errors-as-values/612a159dfd0bf8636d76b813"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Away from exceptions: errors as values](https://humanlytyped.hashnode.dev/away-from-exceptions-errors-as-values?utm_source=hashnode&utm_medium=feed)

Programming with exceptions is difficult and inelegant. Learn how to handle errors better by representing them as values.

Aug 28, 2021 · 8 min read · humanlytyped.hashnode.dev  
Updated Aug 30, 2021  
Read the article

-   [#typescript](https://hashnode.com/tag/typescript)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#error-handling](https://hashnode.com/tag/error-handling)
-   [#programming](https://hashnode.com/tag/programming)

## Written by

[Barisere Jonathan](https://hashnode.com/@barisere)

@barisere

  
[View profile](https://hashnode.com/@barisere)

## Responses 3

Markdown supported · ⌘↵ to post

[Capi Etheriel](https://hashnode.com/@barraponto)

[Aug 30, 2021](https://hashnode.com/posts/away-from-exceptions-errors-as-values/612a159dfd0bf8636d76b813/comment/612cd67a2858872661b9db25)

That is hardly a fair example of error composition.

For starters, `Number.parseInt` should throw or be replaced with a throwing `parseInt` function (hiding the details).

As for the `value > 3`, we should not treat an error we raised ourselves! We should either have the caller deal with it or not throw at all: just use `Math.min` and be done with it.

[Barisere Jonathan](https://hashnode.com/@barisere)

[Aug 30, 2021](https://hashnode.com/posts/away-from-exceptions-errors-as-values/612a159dfd0bf8636d76b813/comment/612cd67a2858872661b9db25#reply-612cdc652858872661b9dc3e)

That's correct. I'll rework the example later today. Thanks for pointing that out.

[Barisere Jonathan](https://hashnode.com/@barisere)

[Aug 30, 2021](https://hashnode.com/posts/away-from-exceptions-errors-as-values/612a159dfd0bf8636d76b813/comment/612cd67a2858872661b9db25#reply-612d2c6b2858872661b9e883)

I've updated the article with a modified example. I hope this works better.

[Nate Finch](https://hashnode.com/@natefinch)

[Aug 30, 2021](https://hashnode.com/posts/away-from-exceptions-errors-as-values/612a159dfd0bf8636d76b813/comment/612cc3b42858872661b9d7c2)

Maybe you have regular readers that know what language you always talk about, but for me, I had no idea what programming language you were talking about until I saw the tags at the bottom of your post. You might want to put "In TypeScript....." near the beginning of your articles so people who get here from random places on the internet know what you're talking about.

[Barisere Jonathan](https://hashnode.com/@barisere)

[Aug 30, 2021](https://hashnode.com/posts/away-from-exceptions-errors-as-values/612a159dfd0bf8636d76b813/comment/612cc3b42858872661b9d7c2#reply-612cc91a2858872661b9d8c0)

Thank you, Nate. I'll update this article later today, I'll indicate the language too.
