<body> <div id="error"> </div> <script> try{ if(x==1) { throw "x must not be 1"; } } catch(err) { document.getElementById("error").innerHTML = err; } </script> </body>