387Chapter 16Window and Frame ObjectsWhen the browser starts, the window.onerrorproperty is . In this state, allerrors are reported via the normal JavaScript error window or message. To turn off erroralerts, set the window.onerrorproperty to invoke a function that does absolutely nothing: function doNothing() { return true; } window.onerror = doNothing; To restore the error messages, reload the page. You can, however, also assign a custom function to the window.onerrorproperty. This func- tion then handles errors in a more friendly way under your script control. Whenever errormessages are turned on (the default behavior), a script error (or Java applet or class excep- tion) invokes the function assigned to the onerrorproperty, passing three parameters: .Error message .URL of document causing the error .Line number of the errorYou can essentially trap for all errors and handle them with your own interface (or no usernotification at all). The last statement of this function must be return trueif you do notwant the JavaScript script error message to appear. If you are using LiveConnect to communicate with a Java applet directly from your scripts, you can use the same scheme to handle any exception that Java may throw. A Java exceptionis not necessarily a mistake kind of error: Some methods assume that the Java code will trapfor exceptions to handle special cases (for example, reacting to a user s denial of access whenprompted by a signed script dialog box). See Chapter 44 on the CD-ROM for an example oftrapping for a specific Java exception. Also, see Chapter 31 for JavaScript exception handlingintroduced for W3C DOM compatible browsers. ExampleIn Listing 16-10, one button triggers a script that contains an error. I ve added an error han- dling function to process the error so that it opens a separate window and fills in a textareaform element (see Figure 16-5). A Submit button is also provided to mail the bug informationto a support center e-mail address an example of how to handle the occurrence of a bug inyour scripts. Listing 16-10:Controlling Script Errors