Can't catch DB exception
Hey, why I can't catch a DB exception? here's my code:
var Barrel = {} || Barrel;
Barrel.DB = function () {
this.db = null;
this.dbname = null;
};
Barrel.DB.prototype.open = function () {
if ( null === this.dbname ) {
throw "dbname can not be empty";
}
try {
if ( null === this.db ) {
this.db = Titanium.Database.open( this.dbname );
}
} catch ( e ) {
throw e;
}
}
Barrel.DB.prototype.insert = function ( table, data ) {
// some code ...
try {
this.open();
this.db.execute( query, values );
var id = this.db.lastInsertRowId;
Ti.API.debug( "id: " + id );
} catch ( e ) {
Ti.API.debug( e ); // never printed
Ti.API.debug( "n: " + e.name ); // never printed
Ti.API.debug( "m: " + e.message ); // never printed
throw e; // never fired
}
return id;
}
function Product() {
this.dbname = "barrel.db";
}
Product.prototype = new Barrel.DB();
Product.prototype.constructor = Product;
var product = new Product();
product.insert( "notices", { col1: "woot", col2: "woot2", col3: null, col4: "null" } );
The exception on the TRACE log is something like this:
[TRACE] I/Database( 413): sqlite returned: error code = 1, msg = table notification has no column named productId
[TRACE] E/TiDB ( 413): (kroll$2) [28,312889] Error executing sql: table notification has no column named productId: , while compiling: INSERT INTO notification (productId, name, price, image, users, url) VALUES (?, ?, ?, ?, ?, ?)
[TRACE] E/TiDB ( 413): android.database.sqlite.SQLiteException: table notification has no column named productId: , while compiling: INSERT INTO notification (productId, name, price, image, users, url) VALUES (?, ?, ?, ?, ?, ?)
So, why I can't catch the exception? the exception is thrown, isn't just catch it?
Thanks.
2 Answers
-
Have you tried a newer Continuous Integration Build? we made a bug fix to correctly throw more exceptions back to the JavaScript context.
-
I am also looking to catch DB exceptions, but it doesn't work with SDK 1.7.1, too…..now 1.7.2 is out, but I cannot upgrade my app yet…
To confirm by others, and especially Don or Paul, I've read in some posts that the Database exceptions cannot be caught in the Simulator, but that they are "working" and can be caught when installed in devices…
Can this be confirmed ??
Thank you in advance !