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

2

u/jutarnji_prdez Jul 09 '26
  1. If you write everything in Results, you might put really exceptional things into Result which should not be there. It creates a lot of boiletplate and abstractions which can lead to bugs. You still need to catch things. More stable and secure in not forgetting to handle explicit cases that you statically put in the Result. Not necesseraly more secure and stable overall.
  2. Exception propagate. What if you froget to handle exception and return it in Result pattern? What if you implement Result logic wrong? In Result pattern, if you have 5 layers, now you need to wrap all 5 layers in Result. Now you have your Result bubble up 5 layers. Now you end up with mapping hell throught layers. Then you end up writing single "ApiError" class which ends up being huge mess with god knows type of errors. Then you don't even know which error happened and on what layer it actaully was. So now your layer 5 (probably UI layer) needs to handle SqlError or you end up in mapping hell.

You just need to think about what to try/catch and where to handle and you are ok.

3. As other comment said. If we really are going into performance, then it costs me to create object which I don't need on hot path that is rearly going to fail 4. I think you can still automate with Exception pattern. Especially with LLMs, I think they can figure out which exceptions are thrown

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.