自定义异常是在日常开发中经常使用到的;
异常类代码:
调用代码
异常类代码:
1 /// <summary>
2 /// Represents the exception that is thrown when attempting an action that ....
3 /// </summary>
4 class SampleException : Exception
5 {
6 private string cMessage = string.Empty;
7 public override string Message
8 {
9 get
10 {
11 return cMessage;
12 }
13 }
14 public SampleException(string pstrMessage)
15 {
16 cMessage = "this is sampe...";
17 }
18 }
2 /// Represents the exception that is thrown when attempting an action that ....
3 /// </summary>
4 class SampleException : Exception
5 {
6 private string cMessage = string.Empty;
7 public override string Message
8 {
9 get
10 {
11 return cMessage;
12 }
13 }
14 public SampleException(string pstrMessage)
15 {
16 cMessage = "this is sampe...";
17 }
18 }
调用代码
try
{
ProcessOneRequest(tokens[0], tokens[1]);
}
catch (SampleException ex)
{
Utility.WriteLog(“this is sample!!”);
}
{
ProcessOneRequest(tokens[0], tokens[1]);
}
catch (SampleException ex)
{
Utility.WriteLog(“this is sample!!”);
}