by Keyvan Nayyeri via Keyvan Nayyeri on 8/22/2006 5:03:38 PM
As same as Event Logs, Community Server has its own mechanism to handle application exceptions and log them. Community Server logs all exceptions and save them into database in cs_Exceptions table. These exceptions are available to site administrators via Exceptions Report page in Control Panel (http://[SiteAddress]/ControlPanel/Tools/Reports/ExceptionsReport.aspx).
All you need to deal with any kind of exception in Community Server is an object, CommunityServer.Components.CSException.
Generally you have six constructors to create a new CSException object. But you can suppose these constructors in two groups: one for any exception that occurs for whole application and another one specially for exceptions that occur for creating a new user.
The importance of exceptions that occur on user creation and and the need of having them in a separate group lead to create a separate kind of enumeration type for them. While constructing a new CSException regardless of which constructor are you using you must pass one of two enumeration types as parameter: CSExceptionType or CreateUserStatus. Each of these two enumerations have a list of many possible exceptions that may occur for your application during its life cycle or on creating a new user. By choosing right enumeration value, you let Community Server to log the exception in right category.
Following sample is for creating a new instance of CSException for whole application exceptions:
private void MyMethod()
{
try
// Some operations occur with an error
}
catch
CSException ex = new CSException
(CSExceptionType.ApplicationStop);
And below is a sample of creating a new instance of CSException object for an exception that occurs on user creating:
(CreateUserStatus.DisallowedUsername,
"Disallowed name token");
Note that as same as .NET exceptions you should catch the exception on catch block as follows:
catch (CSException ex)
// Logic for exception
CSException itself has some properties that you should set when you create a new instance based on the type of exception you need to throw.
private void MyMethod(string username, string password,
string email)
User user = new User();
if (DisallowedNames.NameIsDisallowed(username))
(CreateUserStatus.DisallowedUsername);
ex.DateCreated = DateTime.Now;
ex.DateLastOccurred = DateTime.Now;
ex.HelpLink = "http://communityserver.org/forums";
ex.IPAddress = CSContext.Current.Context
.Request.UserHostAddress;
ex.UserAgent = CSContext.Current.Context
.Request.UserAgent;
ex.Log();
throw ex;
user.Username = username;
user.Password = password;
user.Email = email;
Users.Create(user, true);
Note that I used CSException.Log() method to log my exception before throwing it.
Original Post: CS Dev Guide: CSException
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.