1. Write a custom error handling JavaScript function called processErrors that handles a custom error by assigning it to the onerror event handler. Include the block of JavaScript statements needed to pass the arguments sent by the JavaScript interpreter into the processErrors function, send an alert message with the agreements, return, and write the event handler that calls the processErrors function.

Question: Does the following code include the requirments to the above question?

function processErrors(errMessage, errURL,
errLineNum) {
window.alert("The fi le " + errURL
+ " generated the following error: "
+ errMessage + " on line " + errLineNum);
return true;
}
window.onerror=processErrors;

This is the code from my text. If I understand correctly, errMessage, errURL, and errLineNum are the arguments passed by the JavaScript interpreter. Are these always the arguments that will always be passed anytime you specify a custom error-handling function by assigning it to the onerror event handler?

Does the following portion of the code complete the requirments: send an alert message with the agreements, return, and write the event handler that calls the processErrors function.

window.alert("The fi le " + errURL
+ " generated the following error: "
+ errMessage + " on line " + errLineNum);
return true;
}
window.onerror=processErrors;

Can someone please help shed some light on this or at least direct me. I somewhat understand but when I start to put it all together I feel like I am just throwing stuff out there with no real organization. Any and all help will be greatly appreciated. Thank you.

Perhaps you forgot the brackets when calling the function?
window.onerror=processErrors();

window.onerror=processErrors();

I don't think it is correct because the function takes 3 arguments but the assignment takes none. It could be window.onerror = function(...) { ... } but the homework said to create a function called processErrors.

To explain what you need to do, I will break everything down into pieces...

//Write a custom error handling JavaScript function called processErrors
//You got this part off the book
function processErrors(...) { ... }

//that handles a custom error by assigning it to the onerror event handler.
//This part too
window.onerror = processErrors;

//Include the block of JavaScript statements needed to pass the arguments sent by the JavaScript interpreter into the processErrors function,
// that means the arguments listed inside the ()
function processErrors(errMsg, errUrl, errNum) { ... }

//send an alert message with the agreements,
//That's what you are sending an alert message
window.alert("The file " + errURL + " generated the following error: " + errMessage + " on line " + errLineNum);

//return,
//This is one vauge requirement. What do you need to return is not defined...
//You could return 'true' but you could simply use 'return' too.
return true;

//and write the event handler that calls the processErrors function.
//You are missing this one; however, it becomes an unreachable statement.
//In other words, once your function call 'return', nothing after that
// in the same scope will be reachable. Stupid requirement...
//Anyway, the way to find out who is the caller is...
arguments.caller.toString()

//So if I put all together again...
function processErrors(errMessage, errURL, errLineNum) {
    window.alert("The file " + errURL + " generated the following error: " + errMessage + " on line " + errLineNum + ", and the caller is "+arguments.caller.toString());
    return true;
}
window.onerror=processErrors;

Hope this is what you are looking for...

Taywin,

Thank you so much for your response. I had to turn the assignment in last night but it is nice to have the breakdown you provided. At least with your breakdown I can understand what some of this means! Very confusing stuff...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.