Click here to Skip to main content
15,889,335 members
Articles / Programming Languages / C#

Using Multiple Return Values instead of Exceptions

Rate me:
Please Sign up or sign in to vote.
5.00/5 (14 votes)
4 Jan 2021CPOL8 min read 18.4K   16  
Discussion about how Exceptions are different from expected errors, and how to return errors in your methods using multiple return values
Many developers believe that exceptions should not be used as control flow, and argue that exceptions should be used only for non-expected errors, while return codes should be used for regular expected situations. This article explains how you can return errors as return codes, and discusses multiple options using Tuples, ValueTuples, Generics, and a combination of both.

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
I'm passionate about building things since I was born and passionate about computers and programming since I was a kid. I taught myself programming when I was 12 by reading some BASIC programming books and never stopped since then, having played and worked with dozens of technologies.

I have more than 20 years of work experience, having played both technical and management roles, and having worked for companies in many different sectors, including Financial Institutions, Healthcare, and Startups.

I have a Bachelor's degree in Computer Science from University of São Paulo, and an MBA degree from Fundação Getúlio Vargas, both top-ranked universities in Latam. Born and raised in Brazil, lived in Chile for a while, now living in Florida (Fort Lauderdale Area).

If you like my articles please check and follow me on https://github.com/Drizin

Comments and Discussions