C
C#3y ago
surwren

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
333fred
333fred3y ago
Highly recommended reading: $errormodel
MODiX
MODiX3y ago
Joe Duffy - The Error Model
Joe Duffy's Blog | Adventures in the high-tech underbelly
333fred
333fred3y ago
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
surwren
surwrenOP3y ago
I need to read through- thanks
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Accord
Accord3y ago
✅ This post has been marked as answered!

Did you find this page helpful?