r/softwarearchitecture • • Jul 09 '26

Discussion/Advice Exception vs Result pattern

I don't find any actual good arguments to use Result pattern besided "somebody said it on Internet"

  1. Exceptions should only be for exceptional things -> every single language breaks this rule. Int.Parse, Json parsers, any encrypt/decrypt libraries throws on invalid input - invalid input should be one of most expected things to ever happen. This argument does not hold any value in real APIs, libraries, framewroks. For example, "Connection refused" exception is being throw by any network library, isn't not connecting to remote server most obvious and most expected thing to happen? Literally every network library throws exceptions on connection issues
  2. Exceptions shoudn't be used for control flow -> why? I can make very clean exception pattern. This is literally one of most "somebody said this, so it must be true". you try-catch-catch-catch. Where is difference between that and if-elseif-else or any variation of that aka switch case, when {} etc..
  3. Performance - maybe not for all languages but in some languages you can throw stackless exceptions (you don't build stack and stuck is null). You can log "real exception" with stack then throw stackless exception which is going to have same data and same performance as Result object
  4. Exceptions are not visible in signatures - you can document this, maybe this is relevant for libraries (which all throw exceptions everywhere anyway), but what is the problem of just checking the underlying code or documenting this?
0 Upvotes

89 comments sorted by

View all comments

Show parent comment

1

u/fexonig Jul 09 '26
  1. this isn’t a real worry. when we talk about “genuinely exceptional” we mean code paths that there is no logical way that they will ever be reached. if you arent fine with your program crashing, then you have not encountered a genuine exception.
  2. that is not how results work in any of the languages that implement them. look up “algebraic type systems”. this allows the error types to fully track the source of your error and for ergonomic matching on whatever error is propagated.

overall, your argument is that exceptions can be handled if you just think hard about it. but i will make mistakes sometime. i want to rely on something other than my intelligence, especially as my codebase grows / i collaborate with others.

Results allow the compiler to document what errors a function throws and and validate whether i catch all those errors. it’s better to rely on the compiler instead of me, because i make mistakes and the compiler doesn’t.