Hi, I have a json string that I'm getting from the server. I loop over one of the objects and need to delete from a sqlLite database.
here's the code:
var dal = require('/commonJS/Dal').openDB(); try { // Insert recived catalogs data into database for (var i = 0; i < data.CatalogData.length; i++) { var oCatalog = data.CatalogData[i]; var iServerId = parseInt(oCatalog.CatalogId).toString(); // delete catalog from db var count = dal.execute('delete from Catalogs'); //alert(count); } } catch(ex) { alert(ex.message); } dal.closeDB();and once I run this the app crashes and closes the emulator (iPhone). It's ok - I know why it's crashing (because it can't find the table I'm deleting from):
2011-11-08 14:28:07.410 IMS[1522:5d03] *** Terminating app due to uncaught exception 'org.ims.TiDatabaseProxy', reason: 'invalid SQL statement. Error Domain=com.plausiblelabs.pldatabase Code=3 "An error occured parsing the provided SQL statement." UserInfo=0x6a3eff0 {com.plausiblelabs.pldatabase.error.vendor.code=1, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.pldatabase.error.query.string=delete from Catalogs, com.plausiblelabs.pldatabase.error.vendor.string=no such table: Catalogs} in -[TiDatabaseProxy execute:] (TiDatabaseProxy.m:136)' *** Call stack at first throw:my question is - why did the app crash? the entire thing is wrapped inside a
try catch. it should have alerted the error caught by the catch statement.
any ideas?
Thanks
2 Answers
Unfortunately, not all error in Titanium are catchable.
Shlomi,
In your commonjs library, add a try/catch wrapper to your DB calls within the db abstraction functions. See if having the try/catch closer to the error point might work.
Take a look at this thread and see if testing on an actual device will catch the error.
Your Answer
Think you can help? Login to answer this question!