在函数内部有一段代码try
{
string str;
if(str == null)
{
throw new System.Exception("文本为NULL");
}
}
catch(Exception e)
{
....
}
在catch(Exception e) 里面就catch不到throw的这个异常了. 请勿是怎么回事呀?
{
string str;
if(str == null)
{
throw new System.Exception("文本为NULL");
}
}
catch(Exception e)
{
....
}
在catch(Exception e) 里面就catch不到throw的这个异常了. 请勿是怎么回事呀?
try
{
}
catch(Exception e)
{
throw e;
}
try
{
string str= null;
if(str == null)
{
throw new System.Exception("文本为NULL");
}
}
catch(Exception ex)
{
throw ex;
}
試下這斷代碼
我也觉得很怪,呵呵
只是想试试语法而已
之后,
外面的那个try 好像根本就catch不到 new的这个异常
你首先先给 str 一个初始值撒,
这里可以这样 str = null
例子如下
try
{
string str = null;
if (str == null)
{
throw new System.Exception("文本为NULL");
}
}
catch (Exception ee)
{
Response.Write("xxx");
}
{
string str;
if(str == null)
{
throw new System.Exception("文本为NULL");
}
}
catch(Exception e)
{
Response.Write(e.Message);
}可以抓到你要抛的异常
你试试?
我这里确实不行
代码再贴下
try
{
string str = null;
if (str == null)
{
throw new System.Exception("文本为NULL");
}
}
catch (Exception ee)
{
Response.Write("xxx");
}