Jump to content
  • Advertisement
Sign in to follow this  
Quat

C# exceptions

This topic is 4113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, In C# and .NET programming are exceptions the recommended mechanism to handle errors? Does anyone ever return error codes in C#?

Share this post


Link to post
Share on other sites
Advertisement
Yes, Exceptions should be used for errors. The MS Design Guidelines say:
Quote:
Do not return error codes. Exceptions are the primary means of reporting errors in frameworks.


IMHO, this is a pretty good idea :-)
Constantly checking return codes isn't very convenient.

Share this post


Link to post
Share on other sites
Exception handling is the way to go with .Net. Many of the the .Net functions do not return anything so you couldn't return code check them.

theTroll

Share this post


Link to post
Share on other sites
The corollary to that statement is that you shouldn't use exception handling for things that aren't errors. Example: Parse() vs. TryParse(). Parse() throws an exception if the input string can't be turned into a object of the appropriate type. TryParse() returns true or false indicating if the conversion succeeded. The former is used when you know that the string should be of the right type and the latter if you're not sure.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!