JavaScript exception handling

Source: Internet
Author: User
Tags exception handling

Examples of common exception errors are as follows:
Name Error name
Number error
Description description
Message error messages

Common exceptions
Evalerror
Rangeerror
Referenceerror
SyntaxError
TypeError
Urierror

Code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> exception Handling in JavaScript-www.cxybl.com</title>
<meta name= "Content-type" content= "Utf-8" >
<meta name= "Author" content= "" >
<meta name= "Keywords" content= "" >
<meta name= "Description" content= "" >
<script language= "JavaScript" >
<!--
Four properties common to exception objects
/*
try{
alert (result);
}catch (e) {
Alert ("Abnormal name:" +e.name);
Alert ("Exception number:" +e.number);
Alert ("Descriptive information of the exception:" +e.description);
Alert ("error message for exception:" +e.message);
}
*/

Throw an exception throw way
Requires the user to enter a number greater than or equal to 0 to less than or equal to 10, and if the value entered is less than 0, the prompt input cannot be less than 0; If you enter a value greater than 10, you are prompted to enter a number that is not a numeric type.
/*
try{
var result=prompt ("Ask the user to enter a number from 0 to 10");
if (result<0) {
throw new Error ("-1", "input value cannot be less than 0");
}else if (result>10) {
throw new Error ("-2", "the value entered cannot be greater than 10");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.