-
Notifications
You must be signed in to change notification settings - Fork 931
Cease throwing bare Exception #1498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cease throwing bare Exception #1498
Conversation
public static double Sqrt(this double numericProperty) | ||
{ | ||
throw new Exception("Not to be used directly - use inside QueryOver expression"); | ||
throw new InvalidOperationException("Not to be used directly - use inside QueryOver expression"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to wrap this exception creation in some method to minimize copy-paste for future extensions/refactorings. So it should look something like:
throw DirectUsageException();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it have to throw at all? Real methods are replaced in queries all the time, so why not here, i.e call Math.Sqrt and be done with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gliljas could do, but in another RP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it have to throw at all? Real methods are replaced in queries all the time, so why not here, i.e call Math.Sqrt and be done with it?
Some cases could be trickier, like the Projection.Concat
where string.Concat
null
handling will not be similar to SQL default null
handling. So this may cause more troubles than simply throwing.
teamcity.build
Outdated
if (brokenTests.Count > 0) | ||
throw new Exception("Previously passing tests have been broken\n\n" + output); | ||
throw new InvalidOperationException("Previously passing tests have been broken\n\n" + output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not InvalidOperationException. This is either need to stay as an Exception
or another exception type, probably from Nant's namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, reverting. This script is currently no more used so changing it is not tested.
{ | ||
if (value != null) | ||
throw new Exception("null component property"); | ||
throw new InvalidOperationException("null component property"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ArgumentException
/ArgumentNullException
I have made more changes than the ones requested in review, especially in |
Throwing the
Exception
class is a bad practice. We should throw at least slightly more specific exceptions.