Microsoft
98-382 · Question #3
You are designing a function that allows you to perform unit tests on other functions in a library. You will invoke each library function by using the eval JavaScript function. If an exception…
To handle exceptions in JavaScript, a 'try...catch' block is used. The code that might throw an error goes into the 'try' block, and the error handling logic goes into the 'catch' block. Correct completion of the code: function unitTest(expression) { try { eval(expression); }…
Perform Troubleshooting and Error Handling
Question
You are designing a function that allows you to perform unit tests on other functions in a library. You will invoke each library function by using the eval JavaScript function. If an exception occurs when invoking a function, you want to display a message box with the following message: The function does not exist. How should you complete the code? To answer, select the appropriate code segment in the answer area. The provided code structure is:
function unitTest(expression) {
{ // First block, needs a keyword
eval(expression);
}
(err) { // Second block, needs a keyword
alert("The function does not exist.");
}
}
Explanation
To handle exceptions in JavaScript, a 'try...catch' block is used. The code that might throw an error goes into the 'try' block, and the error handling logic goes into the 'catch' block.
Correct completion of the code:
function unitTest(expression) { try { eval(expression); } catch (err) { alert("The function does not exist."); } }
Topics
#try/catch#exception handling#eval()#error display
Community Discussion
No community discussion yet for this question.