Wednesday, September 24, 2008

Poor ASP.NET error handling now slightly better

The highlighted part stops the javascript erroring if the erorr message contains CRLF. (Which most of the custom error messages in the system I'm working with do.)
try
{
    ...
}
catch (Exception ex)
{
    DBUtils.RollbackTrans();
    bdyDetail.Attributes.Add("onload", "javascript:alert('" + ex.Message.Replace("\r\n", "\\n")  + "')");
}

1 comment: