Appendix C
JavaScript® Code for Error Handling
Read the directions carefully and write JavaScript® code that addresses the requirements.
Copy your code directly into this appendix document and post your assignment.
1. Write JavaScript® code that anticipates and handles an error for an expected numeric field. This code is executed on keypress, and the entered value is saved for you in a variable called enteredChar. Include the try block of JavaScript® statements needed to check if the character is not a number or a nonalphanumeric character, or if you throw an error message.
2. 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 arguments, return, and write the event handler that calls the processErrors function.
1. function numCheck() { var enteredChar = document.getElementById('numeric_field').value;
var pattern = new RegExp('/^\d+$/'); // numbers only match
if (pattern.test(enteredChar)) { alert("All good!"); } else { try { throw new Error("Invalid numerical character(s) given!"); } catch (e) { alert(e); } }
}
The html is as follows:
<form>
Enter Numeric Value: <input type="text" id="numeric_field" onkeypress="numCheck()">
</form>
2 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;
You May Also Find These Documents Helpful
-
|4th |As the wounded part of the body reacts to the germs, |Certain cells destroy the germs |…
- 300 Words
- 2 Pages
Satisfactory Essays -
Warning alerts represent items that require attention. When the EMS receives warning messages, they are logged like informational messages and a trouble ticket is created. Trouble ticket system can provide information on the number of alerts received and the speed with which these alerts are addressed.…
- 726 Words
- 3 Pages
Powerful Essays -
The 2 ways they can deal with exception one to write code to elegantly handle the exception, in the…
- 442 Words
- 2 Pages
Satisfactory Essays -
Match the activity or purpose on the left with the appropriate description on the right by typing in the corresponding letter under the Answer column.…
- 197 Words
- 2 Pages
Satisfactory Essays -
10. How can you eliminate the possibility that an application error is caused by another application or service running in the background…
- 850 Words
- 4 Pages
Powerful Essays -
|Inform the new employees of all the rules and regulations, go |Be friendly and humorous while going over all the rules and |…
- 416 Words
- 2 Pages
Satisfactory Essays -
| |makes sure that they know what will be happening to them. | | |…
- 372 Words
- 2 Pages
Satisfactory Essays -
7. Does this organization or individual have affiliations that might create a built-in bias toward the information? Explain your answer.…
- 433 Words
- 2 Pages
Satisfactory Essays -
|persuasive essay? |explain why it’s important to use legal drugs for what they’re intended. |…
- 353 Words
- 2 Pages
Satisfactory Essays -
1. Write JavaScript code that anticipates and handles an error for an expected numeric field. This code is executed on keypress and the entered value is saved for you in a variable called enteredChar. Include the try block of JavaScript statements needed to check if the character is not a number or a non-alphanumeric character or if you throw an error message.…
- 255 Words
- 2 Pages
Satisfactory Essays -
Directions: Assume that you are on the school board of your school district and you are tasked with the job of strategic planning for issues facing your district. Complete the matrix below to determine the potential response of each of the religious groups in your community. Use the attached links to research the basic moral and ethical principles believed by each group. Then determine how you believe each group will react to the issue based on what you find. Provide a brief justification for your answer. After completing the matrix, write a 300- to 500-word summary of the significant similarities and differences among the different religious groups.…
- 355 Words
- 2 Pages
Satisfactory Essays -
Going to war and having a traumatic experience there can cause Post Traumatic Stress Disorder, otherwise known as PTSD. This can happen right away or this could even start years after the traumatic period is over. This can cause the person to do things that might be harmful to themselves or to other people.…
- 414 Words
- 3 Pages
Satisfactory Essays -
In scenario one the prevention level being used is the Primary level of prevention. The reason I believe that this method is being used because the services offered through the agency are ones to prevent the abused women from being depressed and leading to other psychological disorders. In this particular scenario I wouldn’t do anything different, I think that the agency has a good plan in effect for dealing with potential hostile or violent situations. Instead of confronting the husband trying to talk rationally with him and defuse the situation while alarming the authorities is the best route for dealing with a person like that. In the case of the wife the programs offered through the agency promote self-worth and help prevent her from feeling bad about herself. Learning new job skills and healthy ways of thinking about oneself should prepare her for an independent lifestyle to provide for her and her children.…
- 507 Words
- 2 Pages
Satisfactory Essays -
> key characteristics of function declarations is function declaration hoisting, whereby function declarations are read before the code executes.…
- 1085 Words
- 5 Pages
Powerful Essays -
var UA = confirm("Have you visited the 'Hair styles and Price list' page yet? Yes/No")…
- 335 Words
- 5 Pages
Satisfactory Essays