Jump to content

Error Messages and Special Characters


Recommended Posts

1: With the onerror event, I don't fully get the concept of having it return true or false. For example, this example from the tutorial:

<html><head><script type="text/javascript">onerror=handleErrvar txt=""function handleErr(msg,url,l){txt="There was an error on this page.\n\n"txt+="Error: " + msg + "\n"txt+="URL: " + url + "\n"txt+="Line: " + l + "\n\n"txt+="Click OK to continue.\n\n"alert(txt)return true}function message(){adddlert("Welcome guest!")}</script></head><body><input type="button" value="View message" onclick="message()" /></body></html>

Can someone tell me why the heck it has return true typed in there? I took it out and the code seems fully functional to me. Why do onerror statements return true or false? And do you just CHOOSE how they turn out, like how it seems here, with "return true" being typed out and all? I guess I'm just a little confused on that.2: Could someone tell me of any time you would want to write a throw statement with an object? I know you can do things with a Boolean like throw (true) or a string like throw ("Err") and whatnot, but when would you want to set it off with an object? I don't necessarily need written-out code (though that would be nice), but more of an explanation of at what time this would be useful.3: Has anyone else has problems with getting the special characters to work? I tried them out with alert boxes. Ampersand WORKS, but it also works if I don't even put the backslash before it! And form feed doesn't work, but maybe that one makes sense. :) It's appearing as the symbol for female with the circle on top and then a cross below it. And backspace is appearing as like an inverted bullet. Has anyone else had a similar problem and if so, can they tell me why this is happening?

Link to comment
Share on other sites

1: Hmm. I don't know why that function returns anything, let along returning true. I know with other event handlers, if you return false then the action ceases for that element. For example:

<script type="text/javascript">function handleSubmit() // a.k.a. validate form{	return false;}</script><form id="myForm" action="GET" onsubmit="return handleSubmit();"></form>

If the handleSubmit function returns true, then the submit action takes place and the form is submitted. If, on the other hand, it returns false, the form never submits. Perhaps returning true in an error handler allows other error handlers - if they are defined - to also handle the error.Maybe someone else can answer this one.2: Well, if you had some type global error handler in your application, then you could throw an exception when something happens to an object (e.g. a method is called before a certain property is assigned?) and then the global error handler could see what the message was and decide which action to take. I tend to do object-specific error handling within the object itself. At times, when I use throw to throw an exception, it's mainly for debugging, but I seem to remember other times when it came in handy.3: That I don't know. I tend to only use the javascript alerts for debugging. If I want a more substantial alert to be made to the client, I'll either send the user to an error page, or use something like the ThickBox to display the alert.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...