public class StringNotFound : Exception
{
public string str { get; set; } public StringNotFound()
{
} public StringNotFound(string name)
{
str = name;
} public StringNotFound(string name, Exception innerException)
: base("String Not Found", innerException)
{
str = name;
} public StringNotFound(string name, string message, Exception innerException)
: base(message, innerException)
{
str = name;
}
}
A,B 2个工程在一个solution下,A是类库工程,我在上面定义一个异常类,
步骤:
1.在A中会有代码直接抛出异常: throw StringNotFound(“myName”);
2.B引入类库A工程,然后调用步骤1里的代码。我在B中写个try-cathch语句来捕获异常,try{}
catch(Exception e)
{
Console.WriteLine(e.InnerException.Message);
}我想让在B中捕获的异常信息更具体一些,比如是输出时 ”myName srting Not Found“,请问怎么实现?
{
public string str { get; set; } public StringNotFound()
{
} public StringNotFound(string name)
{
str = name;
} public StringNotFound(string name, Exception innerException)
: base("String Not Found", innerException)
{
str = name;
} public StringNotFound(string name, string message, Exception innerException)
: base(message, innerException)
{
str = name;
}
}
A,B 2个工程在一个solution下,A是类库工程,我在上面定义一个异常类,
步骤:
1.在A中会有代码直接抛出异常: throw StringNotFound(“myName”);
2.B引入类库A工程,然后调用步骤1里的代码。我在B中写个try-cathch语句来捕获异常,try{}
catch(Exception e)
{
Console.WriteLine(e.InnerException.Message);
}我想让在B中捕获的异常信息更具体一些,比如是输出时 ”myName srting Not Found“,请问怎么实现?
{
Console.WriteLine(e.tostring());
}
{
Console.WriteLine(e.Message);
}
{
Console.WriteLine(e.tostring());
}
但是我想让他显示我自己定义的异常类中的"myName srting Not Found",还有一点是有多个异常类,难道我每个都catch一遍?请问怎么做?
public class StringNotFound : Exception
{
public StringNotFound()
{
} public StringNotFound(string name)
: base(name + " String Not Found")
{
}