Exception rethrow

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
6/15/2007 4:05:46 AM
Gravatar
Total Posts 488

Exception rethrow

Examining dbPortal.cs I found much code like this:

try
{
...
}
catch(Exception ex)
{
connection.Close();
throw ex;
}

Why do you use "throw ex;" but not "throw;"? The difference is that the second approach does not reset the stack trace.

6/15/2007 6:46:09 AM
Gravatar
Total Posts 18439

Re: Exception rethrow

I agree examples like that could be better implemented. closing the connection should really be in finally not in catch then there would be no need for catch at all. Then again, trying to close a connection could raise a new exception if the connection object is null or not open for some reason. This could happen in the catch or the finally.

In places where the code is like that I have been going through and changing to use the overloads that use connection string instead of connection and removing the try catch completely. By using the overlaods that use connection string the sqlhelper can manage the connections.

Feel free to do more of the same if you want to help clean those up. Its not really a high priority for me I just clean up whenever I'm visiting those methods or methods nearby.

Joe

 

6/15/2007 6:49:59 AM
Gravatar
Total Posts 18439

Re: Exception rethrow

If you do decide to help with those cleanup chores, there is another thing I'm cleaning up casually.

If you see method signatures with upper case params like this:

public static bool Role_Delete(int RoleID) {...}

change them to start with lower case like this:

public static bool Role_Delete(int roleID) {...}

Thanks,

Joe

You must sign in to post in the forums. This thread is closed to new posts.