javascript 自定义错误信息

只支持firefox & opera

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>

 <body>
  <script type="text/javascript">
  <!--
  function add(a,b){
	if(a!=b){
		debug("a != b",(new Error).lineNumber);
	}
  }

  function add2(a,b){
	if(a!=b){
		debug2("a != b",(new Error).lineNumber);
	}
  }

	function debug(msg,ln){
		try{throw new Error(msg);}
		catch(error){console.log("Error Message: "+error.message+" ,line NO.:"+ln);}
		finally{return false;}
	}
	function debug2(msg,ln){
		console.log("Error Message: "+msg+" ,line NO.:"+ln);
		return false;
	}
  //-->
  
  </script>
<a href="javascript:void(0)" onclick="add(1,2);">sssssssssssssssssssssssssssss</a>
<br>
<a href="javascript:void(0)" onclick="add2(1,2);">sssssssssssssssssssssssssssss</a>
 </body>
</html>


posted @ 2011-10-28 15:20  lein.wang  Views(170)  Comments(0Edit  收藏  举报