View Full Version : supress errors?
ASAAKI
10-07-2002, 09:23 PM
can i suppress an error message, and not let it appear at all?
Roy Sinclair
10-07-2002, 10:03 PM
Yes, there are several methods. Which method is best depends on the target browser(s). The oldest is the onerror event which is supported NN3+ and IE4+ while you need IE5+ and NS6+ to use the try { -- statements to run -- } catch { -- statements if an error occurs --} finally { -- optional part with statements to run regardless of the occcurence of an error --} form of error handling.
ASAAKI
10-08-2002, 07:24 AM
sorry i didn't ask my real question: exactly how can u make the error just not appear?
i tried something like onerror=null;
or is null; not in javascript?:confused:
the error i get is 'Object required'. i know why it's coming and i tried to avoid it, but it does show it up at the end. it doesn't affect the program but it's certainly annoying. i want to get rid of it!:mad:
joh6nn
10-08-2002, 07:28 AM
window.onerror = function() {
return false;
}
glenngv
10-08-2002, 07:39 AM
Originally posted by joh6nn
window.onerror = function() {
return false;
}
i believe that it's return true
window.onerror = function() {
return true;
}
and i used it in my intranet site.
here's a reference http://www.devguru.com/Technologies/ecmascript/quickref/evhan_onerror.html
ASAAKI
10-08-2002, 07:42 AM
thanx, it works:)
shuda guessed :o
that was to john. by the time i submitted it, glenn's post was up, so thanx to glenn too, because, very interestingly, they both work!
joh6nn
10-08-2002, 08:03 AM
i've seen it as both return true, and return false, and for some reason, some times one works, some times it's the other. on my own site, return false seems to be the way to go. if you think about it, return false is the way it ought to be; return false is supposed to cancel the default action of the browser. the only documented exception that i know of, is the mouseover event.
if anyone has an explanation, or a guess at the ambiguous behaviour of the error event, i'd love to hear it.
glenngv
10-08-2002, 08:27 AM
there are lots of references that tell that you have to return true to cancel the default error box. here are some:
http://caucuscare.com/~roth/JAVASCRIPT/refp_449.htm
http://javascriptkit.com/javatutors/error5.shtml
maybe, to make it work consistently you have to put this at the very first line of the first script tag like this:
<html>
<head>
<script language="javascript">
window.onerror = function() {
return true;
}
//other codes here
}
</script>
<script language="javascript" src="external.js"></script>
<script language="javascript">
function test(){
}
//other codes here
</script>
</head>
joh6nn
10-08-2002, 08:58 AM
see, i actually wrote my own full fledged onerror event handler, though (which is to say, it's not just an empty function), and it's not the first line of code, nor does it use return true, and it seems to work pretty well.
glenngv
10-08-2002, 11:32 AM
test it with NS6 and compare it (return true and return false) and see the Javascript Console window to see the result.
joh6nn
10-08-2002, 07:17 PM
i use Moz 1.1, both to browse and develop, and i get no errors at all. none in IE, either, not that that means anything.
glenngv
10-09-2002, 01:47 AM
run this code in NS6.2 and Moz1.0 while the JavaScript Console is open. Toggle through return true and false then see which error is suppressed.
<html>
<head>
<script>
window.onerror = function() {
alert('error occurred.')
return true;
//return false;
}
alert(undefinedVar);
</script>
</head>
<body>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.