javascript 中的异常处理
2006-04-12 16:46
387 查看
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>测试javascript中的trycatchfinally</title>
<script language="javascript">
<!--
function initException(Num,Msg)//define an Exception(define an new object)
{
this.ErrorNumber=Num;//error's number
this.ErrorMessage=Msg;//error's message
}
function CreateException()
{
ex=new initException(1,"Created!");//create the excepion (create an new instance of initException)
throw ex;//throw ex
}
function test()
{
try
{
CreateException();
}
catch(ex)//catch the ex
{
if(ex instanceof initException)//if the exception is our target,do something
{
alert(ex.ErrorNumber+ex.ErrorMessage);
}
else//else throw again
{
throw ex;
}
}
finally
{
alert("end");//do something finally
}
}
-->
</script>
</head>
<body>
<form>
<input type="button" name="testbutton" value="testbutton" onClick="test()">
</form>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>测试javascript中的trycatchfinally</title>
<script language="javascript">
<!--
function initException(Num,Msg)//define an Exception(define an new object)
{
this.ErrorNumber=Num;//error's number
this.ErrorMessage=Msg;//error's message
}
function CreateException()
{
ex=new initException(1,"Created!");//create the excepion (create an new instance of initException)
throw ex;//throw ex
}
function test()
{
try
{
CreateException();
}
catch(ex)//catch the ex
{
if(ex instanceof initException)//if the exception is our target,do something
{
alert(ex.ErrorNumber+ex.ErrorMessage);
}
else//else throw again
{
throw ex;
}
}
finally
{
alert("end");//do something finally
}
}
-->
</script>
</head>
<body>
<form>
<input type="button" name="testbutton" value="testbutton" onClick="test()">
</form>
</body>
</html>
相关文章推荐
- 处理JavaScript异常的正确姿势
- javascript中的异常处理
- JavaScript的异常处理
- JavaScript中try...catch和异常处理
- JavaScript异常处理和事件处理
- JavaScript异常处理总结
- JavaScript 的错误(Error)与异常(Exception)处理
- javascript中的异常处理
- JavaScript异常错误处理
- javascript中的异常处理
- JavaScript错误/异常处理
- JavaScript可以使用try...catch来进行异常处理
- JavaScript 异常处理Try{}catch(e){}
- 处理JavaScript异常的正确姿势
- javascript的异常处理之try-catch的用法
- Javascript:拦截所有AJAX调用,重点处理服务器异常
- Javascript异常(exception)处理机制详解 JS、异常Error属性
- javascript异常处理
- JavaScript 中的异常处理
- Javascript ParseInt() IE7 IE8处理0开头字符串异常