Ana*_*and 0 c# asp.net exception-handling exception
在Asp.net(c#)中,我无法正确捕获异常(FileNotFoundException)...我不知道原因.实际上文件不存在..但是catch语句无法捕获异常..这里是代码..
try
{
System.Drawing.Image imgg1 = System.Drawing.Image.FromFile(Server.MapPath("").ToString() + "\\images\\img1.jpg");
}
catch (FileNotFoundException)
{
Response.Write("<script>alert('Please Select and upload Student's Photo');</script>");
}
Run Code Online (Sandbox Code Playgroud)
你可以找出被抛出的类型
try
{
System.Drawing.Image imgg1 = System.Drawing.Image.FromFile(Server.MapPath("").ToString() + "\\images\\img1.jpg");
}
catch (FileNotFoundException)
{
Response.Write("<script>alert('Please Select and upload Student's Photo');</script>");
}
catch(Exception ex)
{
Response.Write("Ex: " + ex.GetType().ToString());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
659 次 |
| 最近记录: |