Skip to content

Conversation

fredericDelaporte
Copy link
Member

Throwing the Exception class is a bad practice. We should throw at least slightly more specific exceptions.

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");
Copy link
Member

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();

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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);
Copy link
Member

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.

Copy link
Member Author

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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be ArgumentException/ArgumentNullException

@fredericDelaporte
Copy link
Member Author

fredericDelaporte commented Dec 22, 2017

I have made more changes than the ones requested in review, especially in ExpressionProcessor where many cases were argument validations.
(This PR still only changes bare Exception to something else, but a bit less to InvalidOperationException.)

@hazzik hazzik merged commit 699db48 into nhibernate:master Dec 23, 2017
@hazzik hazzik added this to the 5.1 milestone Dec 23, 2017
@fredericDelaporte fredericDelaporte deleted the No-bare-exception branch December 23, 2017 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants