Which line of code should you insert at line 09?

You are developing a JavaScript library.
You have the following requirements:
Custom exceptions must include an error message and custom error number.
These exceptions must be thrown when data validation errors occur.
Developers must call the library to easily catch the exception and identify the problem.
You develop the following code. (Line numbers are included for reference only.)

You need to complete the code to meet the requirements.
Which line of code should you insert at line 09?

You are developing a JavaScript library.
You have the following requirements:
Custom exceptions must include an error message and custom error number.
These exceptions must be thrown when data validation errors occur.
Developers must call the library to easily catch the exception and identify the problem.
You develop the following code. (Line numbers are included for reference only.)

You need to complete the code to meet the requirements.
Which line of code should you insert at line 09?

A.
throw new Validatior.Exception (123, “Day of week must be les3 than 7”);

B.
return new ValidationException(123, “Day of week must be less than 7”);

C.
throw ValidationException(123, “Day of week must be less than 7”);

D.
catch ValidationException(123, “Day of week: must be less than 7”);



Leave a Reply 7

Your email address will not be published. Required fields are marked *


hus

hus

None of them are correct. Should be:

throw new ValidationException(123, “Day of week must be less than 7”);

Sam

Sam

must have been the typo the extra . should be removed

Damien

Damien

I have a feeling that whoever added the questions used a figure to text program. That would explain a lot of the typos, like ‘r.’ instead of ‘n’ here.

J

J

that actually explains a lot of this typos. 🙂

Dyna

Dyna

The answer is correct but it should be :
throw new ValidationException.Exception(123, “Day of week must be les3 than 7”);

KBR

KBR

the correct answer with sample:

function ValidationException(nr, msg){
this.message = msg;
this.name = “my exception”;
this.number = nr;
}
function myFunction(dayOfWeek){
if(dayOfWeek > 7){
throw new ValidationException(dayOfWeek, “7 days only!”);
}
}

try {
myFunction(10);
alert(‘ok’);
} catch (e) {
if (e instanceof ValidationException) {
alert(e.message);
} else {
// statements to handle any unspecified exceptions
console.log(e); //generic error handling goes here
}
}