当前位置: 代码迷 >> ASP.NET >> 怎么捕获抛出的错误
  详细解决方案

怎么捕获抛出的错误

热度:9980   发布时间:2013-02-25 00:00:00.0
如何捕获抛出的异常
我在一个类里catch里throw   e   了一个错误,我怎么才可以在调用这个类的地方捕获这个异常呢?
谢谢

------解决方案--------------------------------------------------------
protected void button1_click(object sender,EventArgs e)
{
try
{
aaa();
}
catch(Exception e)
{
Response.write(e.Message);
}
}

private void aaa()
{
throw new Exception( "这个异常是从aaa里抛出的. ")
}

------解决方案--------------------------------------------------------
try
{
Callyourmethod();//maybe throw exception
}
catch(Excepion ex)
{
//if Callyourmethod() throw Exception,you can catch at here
do something here;
}

------解决方案--------------------------------------------------------
看书去~
  相关解决方案