Java Reference
In-Depth Information
Errors, Exceptions, and Warnings
Errors are caused when something goes wrong in a program. They are usually caused by one
of the following:
• system error―there is problem with the system or external devices with which the
program is interacting
• programmer error―the program contains incorrect syntax or faulty logic.; it could
even be as simple as a typo
• user error―the user has entered data incorrectly that the program is unable to handle
As programmers, we often have little influence over how external systems work, so it can be
difficult to fix the root cause of system errors. Despite this, we should still try to catch them
and attempt to reduce their impact by working around the problems they cause. Programmer
errors are our responsibility, so we must ensure they are minimized as much as possible and
fixed promptly. We also should try to limit user errors by predicting any possible interac-
tions that may throw an error, and ensure they are dealt with in a way that doesn't negatively
affect the user experience.
When an error occurs in JavaScript, an exception is thrown that will cause the program to
terminate. For example, trying to call a method that is nonexistent will result in an excep-
<< TypeError: document.unicorn is not a function
An exception will also produce a stack trace . It is often not just a single function or method
call that causes an error, but a sequence of function and method calls. A stack trace will
work backwards from the point at which the error occurred to identify the original function
or method that started the sequence.
JavaScript will also show a warning if there is an error in the code that fails to stop the pro-
gram from running. This means that the program will continue to run after a warning; this
can be problematic, though, since the issue that produced the warning may cause the pro-
gram to run incorrectly.
Search WWH ::

Custom Search