try
{
if (picFileUpload.FileName != String.Empty) //上传控件的文件名不能为空
{
string file = todayurl + picFileUpload.FileName; //得到文件名
picFileUpload.PostedFile.SaveAs(Server.MapPath("../upfile/" + file)); //上传图片
img.ImageUrl = "../upfile/" + file; }
string imageurl = img.ImageUrl;
tb.Text = img.ImageUrl;
Com.updatepic(index, imageurl); //更新数据库图片字段
Com.WebMessageBox("上传成功!"); }
catch
{
Com.WebMessageBox("上传失败,请重新上传!");
}这段代码是在什么样的情况下会产生异常(执行catch里面的代码)?
{
if (picFileUpload.FileName != String.Empty) //上传控件的文件名不能为空
{
string file = todayurl + picFileUpload.FileName; //得到文件名
picFileUpload.PostedFile.SaveAs(Server.MapPath("../upfile/" + file)); //上传图片
img.ImageUrl = "../upfile/" + file; }
string imageurl = img.ImageUrl;
tb.Text = img.ImageUrl;
Com.updatepic(index, imageurl); //更新数据库图片字段
Com.WebMessageBox("上传成功!"); }
catch
{
Com.WebMessageBox("上传失败,请重新上传!");
}这段代码是在什么样的情况下会产生异常(执行catch里面的代码)?
try
{
***
}
catch(Exception ex)
{
ex.message;//就是出错信息撒,有了出错信息,哪里出错不就知道了吗?
}
{
ex.message} 怎么执行ex.message...
我就是想问,这个代码在什么情况下会出现异常
1.上传的文件不存在
2.Server.MapPath("../upfile/" + file);//100%出错
3.img.ImageUrl = "../upfile/" + file;//100%错所以 Com.WebMessageBox("上传失败,请重新上传!");//100%都是这样