惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
L
LangChain Blog
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
J
Java Code Geeks
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
宝玉的分享
宝玉的分享
Jina AI
Jina AI

博客园 - asheng

JavaScript UI选型及Jquery EasyUI使用经验谈 云计算风险识别 五年之痒 敏捷软件开发 嫁给程序员吧!!! Cute Editor for .NET v6.4 Java与.NET的WebServices相互调用 用户体验5大要素 【转】LINQ To XML 入门(3) 【转】LINQ To XML 入门(2) 【转】LINQ To XML 入门(1) 学写Windows Service 微软发布ASP.NET MVC框架1.0正式版 Web定时任务 CSS分类编写方法 JS中错误处理(1) Log4Net OWC画图表 - asheng - 博客园 好员工为什么会变坏
JS中错误处理(2)
asheng · 2009-02-05 · via 博客园 - asheng

throw语句
使用throw语句可以生成一个例外(exception)。结合 try…catch 使用throw语句可以控制程序流程,并生成准确地出错信息。
语法
throw(exception)
其中exception可以是字符串,整数,布尔值,或一个对象。
注意 throw 为小写字母。 使用大写字母会造成 JavaScript 出错!
例1
以下例子根据变量x的值进行不同的动作。 如果x值大于10或小于0,就会抛出一个错误。出错会被 catch 参数捕获,显示适当的出错信息:

<html> 
<head> 
<script type="text/javascript"> 
onerror
=handleErr 
var txt="" 
function handleErr(msg,url,l) 

txt
="There was an error on this page.\n\n" 
txt
+="Error: " + msg + "\n" 
txt
+="URL: " + url + "\n" 
txt
+="Line: " + l + "\n\n" 
txt
+="Click OK to continue.\n\n" 
alert(txt) 
return true 
}
function message() 

adddlert(
"Welcome guest!"

</script> 
</head><body> 
<input type="button" value="View message" onclick="message()" /> 
</body> </html> 

//****************************************
  by: Amen cnblogs博客  转载请注明出处
//****************************************