异常处理: DAL抛异常, BLL,UI 处理异常

DAL层:
    try
        {
            da.Fill(ds); // 填充DataSet
        }
        catch(Exception ex)
        {
            throw new Exception(ex.Message); //文件不存在或补占用等异常!          
         }


UI层:

try
        {
            dt = ole.Import(xlsfile);
        }
      
        catch (Exception ex) //这里抛出的是DAL中的异常信息.注意: ex.Mesage 里面可能有 '', 所以alert('')时有两对'' ,则会alert()出错,正确的做法是: 把ex.Message里的'替换成" 这样就可以了!
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + ex.Message.Replace("\'","\"") + "');", true);
            return;
        }
原文地址:https://www.cnblogs.com/MySpace/p/1599794.html