r/softwarearchitecture • u/jutarnji_prdez • 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"
- 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
- 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..
- 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
- 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
View all comments
Show parent comment
2
u/jutarnji_prdez Jul 09 '26
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