<html>
<head>
<title>Setting an Error handler function</title>
<script language="javascript" type="text/javascript">

function myErrorHandler(err){
    alert("Here's what went wrong:\n"+err);	
	return true;
}

window.onerror=myErrorHandler;

</script>
</head>
<body>
<form>
  <input type="button" value="click me" onclick="javascript:blooberdoober">
</form>
</body>
</html>

Notes: If you would prefer to handle errors in some way other than the default way defined by the browser, you can set the window.onerror property equal to the name of a function.  Just the name -- don't add () or it will cause the function to execute rather than attaching the function to the event as its handler.  One further nuance to this process is that the function you define as the error handler will receive an argument.  In this case I called it "err" but it could be called "e" or something else, too.  It contains a textual description of what went wrong.  Although it is not very helpful (no line number, for instance), it can help you to categorize problems, or perhaps send people to another page based on the kind of error.  

Of course "javascript:blooberdoober" is an error because blooberdoober is not defined anywhere.