Professional Documents
Culture Documents
Chapter 10 Javascript Error Trapping
Chapter 10 Javascript Error Trapping
OBJECTIVES:
➢ Learn why error detection and trapping are needed
➢ Learn the causes of errors
➢ Learn how to detect and handle errors
Errors are flaws that are developed on the course of the program development or deployment. Errors need
to be handled properly so that the program will not crash; That is, prepare the program so it will know what
to do when it faces a certain error.
Causes of Errors
There are times when an error occurs during the development of the program. It could be a logical, a run-
time or a syntax error. When we say logical errors, it means that there is something wrong with the logic or
the flow of the program. It could be because of wrong mathematical expression or the wrong variable was
used for a computation. Run-time error happens when an error has occurred during run time. It could be
because of memory leak. Syntax error happens when the program has encountered a miswritten syntax of
a program. It could be because of wrong capitalization or keywords, lack of quotation marks, etc.
catch (err)
}
The try block will test a block of code for errors. When an error occurs, the catch
block will be executed. The throw statement can be used to make error trapping
more accurate and precise.
Video Links:
https://www.youtube.com/watch?v=79RjHaAYT-4
References:
https://www.w3schools.com/js/js_errors.asp
https://www.w3schools.com/jsref/event_onerror.asp
https://www.w3schools.com/jsref/jsref_throw.asp