简体   繁体   中英

Why is my javascript try/catch block not firing?

No code within my function will run unless I comment out the try/catch code entirely. Why is that? I keep adding code before and after the try/catch and in the try or the catch and nothing will ever run.

<html>
<head>
<script type="text/javascript">
var y=3;
function message()
{
    try
    {
        alert("fdgg");
    }
    catch(err)
    {
        txt="Something went wrong, deal with it!"\n\n";
        txt+="Error crap " + err.message + "\n\n";
        txt+="Click Ok to do stuff.";
        alert(txt);
    }
    alert("67");
}

</script>
</head>
<body>
<input type="button" value="Pooper" onclick="message()");
</body>
</html>

Change

txt="Something went wrong, deal with it!"\n\n";

to

txt="Something went wrong, deal with it!\n\n";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM