如何在JavaScript中捕获异常? [英] How to catch exceptions in javascript?
本文介绍了如何在JavaScript中捕获异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了下面的代码:
var adoConn = new ActiveXObject(ADODB.Connection);
var adoRS = new ActiveXObject(ADODB.Recordset);
var rec = new ActiveXObject(ADODB.Record);
adoConn.Open =DRIVER = {MySQL ODBC 3.51 Driver}; SERVER = 172.25.37.145; +DATABASE = confluence; UID = root; PASSWORD = somePassword; OPTION = 3;
// Connectionstring
alert('Database Connected');
adoConn.Execute(insert into`session`(SessionId,Timestamp)values('+ SessionId +','+ SessionCurrenttime +'));
如果我获得相同的会话ID,那么查询没有执行,因为它是主键数据库。
解决方案
要完成,这里是完整的结构
try {
//你可以抛出异常的代码在这里
} catch(e){
//做异常处理
最后{
//不管它是否工作,在这里做这些东西(清理?)
}
I want to catch exceptions in javascript if an insertion query is not done.
I have written the code below:
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");
var rec = new ActiveXObject("ADODB.Record");
adoConn.Open="DRIVER={MySQL ODBC 3.51 Driver};SERVER=172.25.37.145;" + "DATABASE=confluence;UID=root;PASSWORD=somePassword;OPTION=3";
//Connectionstring
alert('Database Connected');
adoConn.Execute("insert into `session` (SessionId,Timestamp) values ('"+SessionId+"','"+SessionCurrenttime+"')");
If I get the same session id then the query was not executed as it is the primary key in the database.
解决方案
To be complete, here's the full structure
try {
// your code that can throw exception goes here
} catch(e) {
//do stuff with the exception
} finally {
//regardless if it worked or not, do stuff here (cleanup?)
}
这篇关于如何在JavaScript中捕获异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文