0

我在这里有一些代码可以查找图像,但如果图像不存在,它应该显示一些错误文本。它所做的只是显示损坏的图像并且不使用错误文本。在调试时,我看到 catch 异常看到 404 错误,但它只是跳过异常响应文本。这是我的代码:

protected void Page_Load(object sender, EventArgs e)
{
    checkMember(true);

    string acctNumber = Request["acctNum"];
    if (member.findAcct(acctNumber, "CheckImage") != null)
    {
        try
        {
            Response.ContentType = "image/jpeg";
            Response.BinaryWrite(((Member)member).checkImage(acctNumber, Request["ckNum"],DateTime.Parse(Request["date"]), Request["amt"], Request["checkSide"]));
        }
        catch (Exception ex)
        {
            Response.ContentType = "text";
            Response.Write("Error retrieving check image: "+ ex.Message);
        }
    }
    Response.End();

它只是跳过:

catch (Exception ex)
{
    Response.ContentType = "text";
    Response.Write("Error retrieving check image: "+ ex.Message);
}
4

1 回答 1

1

也许您没有遇到异常,您的 if 语句只是返回 false?添加一个 else 来处理错误...

string acctNumber = Request["acctNum"];
if (member.findAcct(acctNumber, "CheckImage") != null)
{
     try
     {
         Response.ContentType = "image/jpeg";
         Response.BinaryWrite(((Member)member).checkImage(acctNumber, Request["ckNum"],DateTime.Parse(Request["date"]), Request["amt"], Request["checkSide"]));
     }
     catch (Exception ex)
     {
         Response.ContentType = "text";
         Response.Write("Error retrieving check image: " + ex.Message);
     }
}
else
{
     Response.ContentType = "text";
     //Exception Message can´t be referenced here
     Response.Write("Error retrieving check image");
}
于 2013-10-03T17:40:01.327 回答