The more JavaScript we code the more errors we'll encounter. Now JavaScript
Tutorial will guide us that his is a fact of life in any
programming environment. Nobody's perfect and, once we build some complex JavaScript,
we'll
find there are sometimes scenarios that result in an error that we didn't think of.
So we can't always prevent errors from occurring, but we can do something about
to handle them. The JavaScript
"Try... Catch" statement helps us to handle JavaScript errors in a very "nice" way.
To use the
JavaScript Try... Catch statement, we take any JavaScript code
we think could potentially result in an error, and
wrap it within the JavaScript "try" statement. We then code what we want to happen in the
JavaScript event of an error and wrap
that in a
JavaScript "catch" statement.
Suppose we got the name of our visitor from some where else and we wish to well come him
or her with his or her name. Like the blow JavaScript code and the below code will result in
an JavaScript error. This is because the variable "username" hasn't been declared yet..