By Stephen Bucaro
user error, or some other cause. The try-catch construct is a way to determine the
cause of an error. Shown below is the basic code for a try-catch construct.
// some code
// code to run if try block fails
Within the try block is the code to be tested for errors while it is being executed.
If an error occurs in the code within the try block, the catch method receives
the error object. The error object has two properties, the number and the description.
Shown below is code that might be placed within the catch block.
// some code
document.write ("Number: ");
document.write (" Description: ");
If you are not sure where an error is coming from, you can use the reverse-binary trouble shooting method.
Start by placing a large block of code in the try section. Then place a smaller block of code within
the try section (about half at a convenient point in the code). Keep placing progressively smaller
blocks of code (about half at a convenient point in the code) within the try section, until you've
isolated the error down to the problem line.
More Java Script Code:
• Java Script alert Message Box
• Get Webpage File Date and File Size
• The do/while Loop
• Search and Replace Strings
• The Conditional Operator
• Java Script Number Object
• The continue Statement
• Java Script Math.cos Method
• The for Loop
• Cookie Power Made Easy