Archive for August, 2007

Free php web host - 1062 Part IV . JavaScript Core Language Reference

Friday, August 31st, 2007

1062 Part IV . JavaScript Core Language Reference In Listing 39-10, the getErrorObj() function adds a custom value to the name property of the newly created error object. The name you assign can be any name, but you want to avoid exception names used by JavaScript or the DOM. Even if you don t know what all of those are, you can probably conjure up a suitably unique name for your error. Down in the catch block, a switch construction branches to treat the two classes of errors differently. Notice that because IE5 s error object does not have a name property, the switch expression (e.name) evaluates to undefined, which forces the defaultcase to execute whenever a native exception is thrown (and you have to be careful about which error object properties you use in the defaultcase statements). In this simplified example, about the only possible problem other than the ones being trapped for explicitly in the tryblock would be some corruption to the page during downloading. Therefore, for this example, the branch for all other errors simply asks that the user reload the page and try again. The point is, however, that you can have as many classifications of custom and system errors as you want and handle them in a single catch block accordingly. Listing 39-10: A Custom Object Exception Throwing a Custom Error Object Exception