我是按照这种方法进行调试的,但try()catch()我没用过
解决方案 »
- 请教关于显示隐藏
- 求一正则表达式
- listbox~~~~(ASP.NET)
- 动态加载js后,当前页面被清空。
- 请教一下向上滚动的相册效果功能(100分,解决马上结贴)
- 如何用js得到url转发前的url(非js的实现方式也可以)
- <input type=file>.value是readonly的, 如何赋值?
- JS改变DIV背景图(求助)
- 这个问题是怎么回事?
- 一个页面两个frame:a1,a2.a1中有个iframe:if2。现要在if2中点击超链接,在a2中显示。怎么写javascript
- 如何取出一组单选按钮中哪一个被选中的索引值?我用document.formname.radioname.index不行
- document.all 和document.layer 到底是什么意思?
有版本限制,你依然可以用 window.onerror=xxx事件来处理
JavaScript 1.4
JavaScript 1.5, NES 6.0: added multiple catch clauses (Netscape extension).
ECMA-262, Edition 3例子:请参考:
Example 2: Throw an object. The following example tests an input string for a U.S. zip code. If the zip code uses an invalid format, the throw statement throws an exception by creating an object of type ZipCodeFormatException. /*
* Creates a ZipCode object.
*
* Accepted formats for a zip code are:
* 12345
* 12345-6789
* 123456789
* 12345 6789
*
* If the argument passed to the ZipCode constructor does not
* conform to one of these patterns, an exception is thrown.
*/ function ZipCode(zip) {
zip = new String(zip);
pattern = /[0-9]{5}([- ]?[0-9]{4})?/;
if (pattern.test(zip)) {
// zip code value will be the first match in the string
this.value = zip.match(pattern)[0];
this.valueOf = function (){return this.value};
this.toString = function (){return String(this.value)};
} else {
throw new ZipCodeFormatException(zip);
}
} function ZipCodeFormatException(value) {
this.value = value;
this.message =
"does not conform to the expected format for a zip code";
this.toString =
function (){return this.value + this.message};
} /*
* This could be in a script that validates address data
* for US addresses.
*/ var ZIPCODE_INVALID = -1;
var ZIPCODE_UNKNOWN_ERROR = -2; function verifyZipCode(z) {
try {
z = new ZipCode(z);
}
catch (e) {
if (e instanceof ZipCodeFormatException) {
return ZIPCODE_INVALID;
}
else {
return ZIPCODE_UNKNOWN_ERROR;
}
}
return z;
} a=verifyZipCode(95060); // returns 95060
b=verifyZipCode(9560;) // returns -1
c=verifyZipCode("a"); // returns -1
d=verifyZipCode("95060"); // returns 95060
e=verifyZipCode("95060 1234"); // returns 95060 1234
2.程序代码要规范,括号要对应,尽量使用tab键
少 ;号
的错误,其实不是少;号,而是你的表达式里没有写合法的运算符之类:
比如:str="sdfsdsdf"+"dfsdfsd
之类的
我常常用的alert();return;逐步确定错误范围;在调试JSP程序的时候是out.println("Run here right!");out.close()
想加入alert显示某处的行数,逐步确定范围。
显示执行语句的行数,JAVASCRIPT中怎么写?
在可以的地方throw(msg)然后用调试器看的.
写错ID就不要提了.
最经常是某个函数返回NULL
在我认为不应该返回NULL的地方,
我就这样写
var obj=SomeFunction();
ASSERT(null!=obj,"var obj=SomeFunction();返回null");function ASSERT(mustbetrue,msg)
{
if(mustbetrue=false)throw(new Error(-1,"ASSERT:\n"+msg));
}
我安装了VS.NET,如果机器配置不高的话,那太慢了。你有好的经验吗,可以发表,让大家都学习一下。
Visual Interdev 的确是一个好东西。
{
if(mustbetrue==false)throw(new Error(-1,"ASSERT:\n"+msg));
}VS.Net是最好的脚本调试器了。
什么都监视得了。。
--------------------
我自己还用自己做的RunScript来进行监视。
不过看不到函数里面的变量了。
XP是快,单位的是w2k!!家里那个还可以
我的是Win2kAS,什么东西都装了。
内存动不动就上300。。打打游戏就上400
我买机子的时候才配个192。。
现在硬盘响死了。
可惜现在内存又贵。。
真不知道怎么办好。
<script>
try{
x=y; // Cause an error.
}
catch(e){ // Create local variable e.
alert(e); // Prints "[object Error]".
alert(e.number & 0xFFFF); // Prints 5009.
alert(e.description); // Prints "'y' is undefined".
}
</script>
当一个异常抛出时,程序的执行不再是线性的,可能跳过某些代码,甚至会由于没有匹配的catch子句而过早地返回。为了确保某一段代码无论发生什么异常都被执行到,需要使用“finally”关键字。finally程序块会在执行try程序块后的代码之前执行。每个try模块都需要至少一个catch和finally子句。一个成员函数返回调用它的函数有两种途径:一个没有被捕捉到的异常;一个return语句,finally子句总是恰好在成员函数返回前处理。
程序清单:
class FinallyDemo{
static void procA(){
try{
System.out.println("inside procA");
throw new RuntimeException("demo");
}
finally{
System.out.println("procA's finally");
}
}
static void procB(){
try{
System.out.println("inside procB");
return;
}
finally{
System.out.println("procB's finally");
}
}
public static void main(String args[]){
try{
procA();
}catch(Exception e);
procB();
}
}运行结果:
c:\>java FinallyDemo
inside procA
procA's finally
inside procB
procB's finally
一般IE提示缺少对象,可能就是变量写错了,或者重复了把 alert() 放在那些可能出错的地方,并且移动它的位置,就可以知道那里出错了
哈哈。。
简单的脚本当然不会有问题。
复杂的脚本,你这次正常了,不能保证下次也正常。
把调试的代码嵌入去,很方便以后的更正的。