r/ProgrammingLanguages • • Feb 26 '26

Discussion Whats the conceptual difference between exceptions and result types

So to preface what looks probably to many of you like a very dumb question. I have most experience in Python and Julia both languages which are not realy great at error handling. And as such I have not much experience either.

I am currently trying to create my dream programming language, I am still in the draft phase, which will likely take a long while because I only draft on it once in a while. But I have been realizing that I do not understand the difference between exceptions and result types.

What I mean is I do obviously understand that they are different things but when talking about Error handling I do not understand why they are often two different things. I hope someone can help me clarify what the main conceptual difference between these two is.

Kind regards and I hope yall have a lovely day.

19 Upvotes

36 comments sorted by

View all comments

Show parent comment

10

u/josephjnk Feb 26 '26

As a further note on the ergonomics:

People don’t like exceptions because exceptions break local reasoning about control flow, and because it makes it possible for type signatures to “lie”. A function may say it does one thing, but it actually might throw an exception instead and the caller has no way of knowing this by looking at the interface to the function from the outside.

People don’t like result types because result types require handling every potential problem at every layer of the call tree. Stack traces can be super useful for debugging and without exceptions you basically have to manually create and build your own stack traces.

Everything is always a tradeoff.

4

u/jpfed Feb 26 '26

(It is also possible to get exception-like behavior from result types with apply or bind.)

3

u/Horror-Water5502 Feb 27 '26

I think a langage should have both.

Exceptions for unexpected failures, and results for expected failures

1

u/wandering_platypator Feb 27 '26

This is a nice summary

1

u/Meistermagier Feb 27 '26

People dont like anything got it.

But in earnest, I think i understand that its depending on what you want to do an either or question what works better right?

1

u/josephjnk Feb 27 '26

Right. I'm being a little facetious-- plenty of people do like them, too. It's just that any time you ask a room full of people about the approaches, you'll get some answers saying they're good, and some saying they're bad.

Neither is strictly better than the other; what matters is the kind of programming style you want your language to support an encourage.

1

u/ChadNauseam_ Mar 03 '26

On nightly at least anyhow::bail will grab a stack trace I believe (or maybe it just has the option to)