1. Put ex. The message is replaced with an arbitrary string, which verifies that the dialog box can be displayed in the Catch statement block using the Response.Write method. The results show success, stating that the problem is in ex. The message.
2. In the program below the breakpoint, you can see ex. The contents of the message are as follows:
Focus is the red circle up the part, there is a carriage return + line symbol, it is estimated that he made the ghost, apart, directly remove it, the code is as follows:
Try
{//... .
} catch (Exception ex)
{
Response.Write ("<script language= ' javascript ' >alert (\" "+ Ex.) Message.replace ("\\r\\n", " ") + "\");</script> ");
}
But that still doesn't work! It's still not showing!
3. After a near-collapse of the exploration, and finally found the problem, indeed is \ r \ NAND, but I replace the wrong way. The next breakpoint to see is \ r \ n (), the \ is already an escape character, used to escape R and N, the true meaning of the expression is carriage return + newline. And I write \\r\\n, is in the former \ escaped after a \,r and N is treated as a normal character, the true meaning of the expression is \ r \ n. That's certainly not the way to replace it! So the correct wording is as follows:
Try
{ //... .
}
catch (Exception ex)
{
Response.Write ("<script language= ' javascript ' >alert (\" "+ Ex.) Message.replace ("\ r \ n", " ") + "\");</script> ");
}
This will be a perfect display!
In fact, there are a lot of such problems on the Internet, the answer is not because they and I made the same mistake, the escape character write more, later encountered a similar problem directly to remove the carriage return + line (such as display a read text, inside contains carriage return line)! Hope this small experience can help everyone!
Reprint: http://blog.csdn.net/yangyuankp/article/details/7630115