w3pop.com :: ÍøÂçѧԺ :: JavaScript :: JS Throw
The throw statement allows you to create an exception.
throwÉùÃ÷¿ÉÒÔÈÃÄã´´½¨Ò»¸öÀýÍâÇé¿ö¡£
The throw statement [throwÓï¾ä]]
How to use the throw statement.
ÔõÑùʹÓÃthrowÉùÃ÷
The throw statement allows you to create an exception. If you use this statement together with the try...catch statement, you can control program flow and generate accurate error messages.
Èç¹ûÄã°ÑthrowÉùÃ÷ºÍtry...catchÉùÃ÷×éºÏÆðÀ´Ê¹Óã¬Äã¿ÉÒÔ¿ØÖƳÌÐòÁ÷³Ì²¢Òý³ö¾«È·µÄ´íÎóÐÅÏ¢
throw(exception) |
The exception can be a string, integer, Boolean or an object.
ÀýÍâ¿ÉÒÔÊÇ´®£¬ÕûÊý£¬²¼¶û»òÊǶÔÏó¡£
Note that throw is written in lowercase letters. Using uppercase letters will generate a JavaScript error!
×¢ÒâthrowÊÇҪСдµÄ£¬²»È»»á³ö´í
The example below determines the value of a variable called x. If the value of x is higher than 10 or lower than 0 we are going to throw an error. The error is then caught by the catch argument and the proper error message is displayed:
ÏÂÃæµÄÀý×Ó£¨½á¹û£©¾ö¶¨ÓÚ±äÁ¿xµÄÖµ¡£Èç¹ûxµÄÖµ´óÓÚ10»òÊÇСÓÚ0¾Í³öÏÖ²»Í¬µÄ´íÎóÌáʾ
<html> |