C
C#2y 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
333fred2y ago
Highly recommended reading: $errormodel
MODiX
MODiX2y ago
Joe Duffy - The Error Model
Joe Duffy's Blog | Adventures in the high-tech underbelly
333fred
333fred2y 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
surwren2y ago
I need to read through- thanks
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Accord
Accord2y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server
More Posts
Hosting an APIWhat would you guys use to host a websocket stream API such as https://docs.deribit.com/ or https://WPF InputBinding with Mouse4 or Mouse5 (X1 or X2)MouseBinding only seems to support Left, middle and right clicking (and the double click versions) (App.Config vs Resources.resx [Answered]What's the main difference between them also why App.Config considered more secure approach ? 2nd quUsing multiple RateLimiters correctly. [Answered]I'm wrapping an API which requires no more than 4 requests per second **and** 200 per hour, I've gotAbstract List of KeyValuePairs```cs public abstract List<KeyValuePair<string, int>> inventory;``` It says I can't do this with a fMAUI navigation to new page with injected viewModelIf you think this belong more into #mobile channel I can move, but I think some of you who are morecatching an exception in an async Task [Answered]I can't seem to catch an exception that is thrown in an async Task, I put try/catch within the asyncpass data onclick from one page to another page in asp nethi all, im trying to redirect a page from **Main Page** to **Sub Page** when i click an item on **MASP NET Core default DI-Container, how pass in constructor not-registered parameter? [Answered]I want to create a Model class using a DI container, services registered in the container are passedShould I return the whole created object in POST or just return the id of that object ?When I creating a post method I find myself repeat what I did in GetById Should I just return the I