> That's a report of what Chrome has experienced, but *not* an > exception. If you put it in a try/catch block, the catch will not > execute.
Ahh OK... I think that might be the source of my confusion... the JS console presents this 'chrome experience' exactly as it would if it really was an exception. > chrome.bookmarks.get(folderID, function(bookmarks) { > if (bookmarks) { //do something useful } > }); > > DOES work currently, at least it does on Windows, and I can't see why > it would be platform-dependent... Well, you're right, it does work... especially if the reported error isn't an exception. I prefer this to checking chrome.extensions.lastError, but will concede that that's probably a personal preference. So that's the answer to the OP. Cheers - rich On Dec 30, 4:04 pm, Daniel Wagner-Hall <dawag...@gmail.com> wrote: > That's a report of what Chrome has experienced, but *not* an > exception. If you put it in a try/catch block, the catch will not > execute. > > chrome.bookmarks.get(folderID, function(bookmarks) { > if (!chrome.extension.lastError) { //do something useful } > }); > > is equally readable imo... I will also point out that the code you posted: > > chrome.bookmarks.get(folderID, function(bookmarks) { > if (bookmarks) { //do something useful } > }); > > DOES work currently, at least it does on Windows, and I can't see why > it would be platform-dependent... > > On 12/30/09, rich <atkins...@gmail.com> wrote: > > > > > I'm using Chromium 4.0.284.0 (35300) Ubuntu > > > I can punch the following code into the JavaScript console (of an > > extension background page where bookmarks are permitted): > > > chrome.bookmarks.get('2323232', function(foo) { > > if (chrome.extension.lastError) { console.log("Not found"); } else { > > console.log("Found"); }}); > > > ....and it definitely throws an exception (in red): > > >> (X) Error during bookmarks.get: Can't find bookmark for id. > > > ... and the little error count in the bottom right goes up by one. > > > What I propose is more like: > > > chrome.bookmarks.get(folderID, function(bookmarks) { > > if (bookmarks) { //do something useful } > > }); > > > Which is easy to read and therefore more than just a convenience, > > IMHO. > > > - rich > > > On Dec 30, 3:39 pm, Daniel Wagner-Hall <dawag...@gmail.com> wrote: > >> Which version of Chrome are you using? On the dev channel, and I think > >> the beta channel, the behaviour is: > > >> It doesn't actually throw an exception when the bookmark doesn't > >> exist. It sets a flag which indicates that the call couldn't return a > >> bookmark (chrome.extension.lastError). This is consistent with most > >> of the other APIs (for instance, all of the chrome.tabs and > >> chrome.windows APIs). The callback is called whether or not the > >> bookmark could be found, and you should check for that flag to see > >> whether or not the bookmark could be found. You don't need to catch > >> an exception, because the execution of chrome.bookmarks.get is > >> asynchronous. > > >> The way it currently works: > > >> chrome.bookmarks.get(folderID, function(bookmarks) { if > >> (chrome.extension.lastError) { console.log("Not found"); } else { > >> console.log(bookmarks); }}); > > >> The way you're proposing: > > >> chrome.bookmarks.get(folderID, function(bookmarks) { if (bookmarks == > >> []) { console.log("Not found"); } else { console.log(bookmarks); }}); > > >> They're basically the same, except checking chrome.extension.lastError > >> is more general purpose (can be mirrored in other APIs), whereas > >> returning an empty array is more specific to this use. I agree that > >> perhaps if the extension couldn't find any bookmarks with that ID, it > >> would maybe be convenient if it returned an empty array as the > >> argument to the callback, as well as setting > >> chrome.extension.lastError, but that would simply be a convenience. > > >> On Wed, Dec 30, 2009 at 3:02 AM, rich <atkins...@gmail.com> wrote: > >> > Well that works so far in that the presence of an uncaught Exception > >> > indicates the bookmark doesn't exist. > > >> > However there is still an uncaught exception. If this is the best way > >> > to use the API then clearly the API is rubbish. > > >> > Wouldn't it be better if an array of BookmarkTreeNodes was passed to > >> > the callback function, like this: function(array of BookmarkTreeNode > >> > results) {...}); > > >> > If there are no results, then the array is empty. > > >> > (This is how chrome.bookmarks.search works) > > >> > thoughts? > > >> > On Dec 30, 1:17 pm, Daniel Wagner-Hall <dawag...@gmail.com> wrote: > >> >> Are you looking for a specific bookmark by ID? Something along the > >> >> lines of: > > >> >> chrome.bookmarks.get(folderID, function(foo) { if > >> >> (chrome.extension.lastError) { console.log("Not found"); } else { > >> >> console.log("Found"); }}); > > >> >> may work... > > >> >> On Wed, Dec 30, 2009 at 1:08 AM, rich <atkins...@gmail.com> wrote: > >> >> > bump! > > >> >> > On Dec 29, 6:54 am, rich <atkins...@gmail.com> wrote: > >> >> >> What is the recommended way to test for existence of a > >> >> >> BookmarkTreeNode that doesn't have a URL (i.e. a folder)? > > >> >> >> chrome.bookmarks.search does not work for non-URL bookmarks (always > >> >> >> returns false) > > >> >> >> The following code is fugly, and doesn't work: > > >> >> >> try { > >> >> >> chrome.bookmarks.get(folderID, > >> >> >> function(){console.log('found')});} catch(e) { > > >> >> >> console.log('not found'); > > >> >> >> } > > >> >> >> So, what is the recommended way to test for existence of a > >> >> >> BookmarkTreeNode that doesn't have a URL (i.e. a folder)? > > >> >> >> - rich > > >> >> > -- > > >> >> > You received this message because you are subscribed to the Google > >> >> > Groups "Chromium-extensions" group. > >> >> > To post to this group, send email to > >> >> > chromium-extensi...@googlegroups.com. > >> >> > To unsubscribe from this group, send email to > >> >> > chromium-extensions+unsubscr...@googlegroups.com. > >> >> > For more options, visit this group > >> >> > athttp://groups.google.com/group/chromium-extensions?hl=en. > > >> > -- > > >> > You received this message because you are subscribed to the Google > >> > Groups "Chromium-extensions" group. > >> > To post to this group, send email to > >> > chromium-extensi...@googlegroups.com. > >> > To unsubscribe from this group, send email to > >> > chromium-extensions+unsubscr...@googlegroups.com. > >> > For more options, visit this group > >> > athttp://groups.google.com/group/chromium-extensions?hl=en. > > > -- > > > You received this message because you are subscribed to the Google Groups > > "Chromium-extensions" group. > > To post to this group, send email to chromium-extensi...@googlegroups.com. > > To unsubscribe from this group, send email to > > chromium-extensions+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/chromium-extensions?hl=en. -- You received this message because you are subscribed to the Google Groups "Chromium-extensions" group. To post to this group, send email to chromium-extensi...@googlegroups.com. To unsubscribe from this group, send email to chromium-extensions+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/chromium-extensions?hl=en.