© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
6 replies
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Minor Error Handling ; TryGetValue returning null [Answered]
C#CC# / help
4y ago
WPF Handling crashes more gracefully. [Answered]
C#CC# / help
4y ago