如何在javascript中捕获异常?

14 javascript error-handling exception

如果没有插入查询,我想在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+"')");
Run Code Online (Sandbox Code Playgroud)

如果我获得相同的会话ID,则查询未执行,因为它是数据库中的主键.

scu*_*ffe 25

完整,这是完整的结构

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?)
}
Run Code Online (Sandbox Code Playgroud)


Koo*_*Inc 1

try {
    adoConn.Execute("insert into session (SessionId,Timestamp) values ('"
                     + SessionId + "','" 
                     + SessionCurrenttime + "')");
} catch(e) {
    /*use error object to inspect the error: e.g. return e.message */
}
Run Code Online (Sandbox Code Playgroud)