Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
catch (Exception ex)
{
    Response.Write("<script>alert('" + ex.Message + "')</script>");
}


in exception it gives runtime error
javascript run time error
how to modify?
Posted
Updated 7-Jul-11 23:36pm
v3
Comments
R. Giskard Reventlov 8-Jul-11 5:33am    
What is the full error message you are getting?

The problem is that ex.Message may contain multiple line breaks which will foul up your javascript. What you should do is post the part you're interested in after it was rendered to your browser. Look at the page source for that and locate the script tag you've generated. You can also try to store the exception message inside a DIV tag and then read that from your javascript code:

C#
catch (Exception ex)
{
    Response.Write("<div id='exceptionDiv'>" + ex.Message + "</div>";
    Response.Write("<script>alert(document.getElementById('exceptionDiv').innerHTML)</script>");

}


Regards,

—MRB
 
Share this answer
 
v3
Comments
Espen Harlinn 8-Jul-11 7:24am    
Good answer, my 5
fjdiewornncalwe 8-Jul-11 8:00am    
Very good. +5
You can try:

Response.Write("<script type='text/javascript'>alert('" + ex.Message + "');</script>");
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900