Error Handling vs Type Enforcement [Answered]
In what scenarios would error handling be more effective/efficient and in what scenarios would only type enforcement be more effective/efficient?
Say for example maybe you don't want variable x to go below 0.
You could enforce this with error handling (try, catch, conditionals) or just assign variable x to be a uint.
Maybe you have a withdraw function from a bank account. You don't want it to go below 0 because then the user can print money by abusing the double negative.
You could definitely apply both methods, how does one know which to apply? Also for other situations not involving bank accounts.
In summary, which situations would error handling be preferred? And in which situations would type enforcement be preferred?
6 Replies
Highly recommended reading: $errormodel
Joe Duffy - The Error Model
Joe Duffy's Blog | Adventures in the high-tech underbelly
But in general, I think you need start by deciding whether the error is something that you expect user code to need to deal with, or whether it's an exceptional case that it couldn't reasonably be expected to handle
I need to read through- thanks
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
✅ This post has been marked as answered!