Sign in to follow this  

C# exceptions

This topic is 3747 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

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
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

This topic is 3747 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this