As I said, a failure of the bookmarks API doesn't happen synchronously, but
rather in the callback function you provide.  Try/catch will do nothing.
 This is by design.  The callback function is *always* called, even on
failure.

Try this line for example:
chrome.bookmarks.get("1", function(bookmark) {
  console.log(bookmark);
  console.log(chrome.extension.lastError);
});

Then try this one:
chrome.bookmarks.get("foobar", function(bookmark) {
  console.log(bookmark);
  console.log(chrome.extension.lastError);
});

In the first one, bookmark is defined and lastError is undefined.  In the
second one, bookmark is undefined and lastError is defined.

http://code.google.com/chrome/extensions/extension.html#property-lastError

So in your test code, RefreshFolder is always called, but sometimes it's
called with null as an argument rather than an array of bookmark nodes.

Erik


On Wed, Dec 16, 2009 at 2:27 PM, Andrew Barfield <barfield2...@gmail.com>wrote:

> Hi Erik,
>
> Thank you for your response. I thought catching the exception would solve
> my problem but oddly it doesn't help at all.
>
> *Here's my situation:* I have some items in localStorage. Each Key is the
> ID of a bookmark folder and the Value with each key is a URI. At timed
> intervals the following code executes. If a bookmark folder isn't
> found (i.e. exception) with the stored ID then that ID should be deleted
> from localStorage.
>
> for(var i=0; i<localStorage.length; i++)
> {
>
>  // Get a folder's info
> chrome.bookmarks.get( localStorage.key(i), RefreshFolder );
>
> }
>
> If you run this code with an inline callback function that prints "i" to
> the console it always prints "3" (Note: localStorage.length == 3). In other
> words I have no way of detecting in the callback function which value of "i"
> lead to the exception.
>
>
> Andrew M. Barfield
> 605C Plum Nearly Lane,
> Wilmington, NC 28403
> 1-910-386-7355
>
>
>
>
> On Wed, Dec 16, 2009 at 5:00 PM, Erik Kay <erik...@chromium.org> wrote:
>
>> The reason is that the function is executed asynchronously, which means
>> that error handling is asynchronous as well.  Usually only argument type
>> validation will actually throw an exception.
>>
>> To catch an error in the actual use of the API itself, check the value of
>> chrome.extension.lastError in your callback.
>>
>> Erik
>>
>>  On Tue, Dec 15, 2009 at 11:27 PM, Drew <barfield2...@gmail.com> wrote:
>>
>>>  Hello,
>>>
>>> Is there any way to catch an exception from chrome.bookmarks.get() ?
>>>
>>> if I try:
>>>
>>>        try
>>>        {
>>>                chrome.bookmarks.get( bookmarkID, fnCallback );
>>>        }
>>>        catch(e)
>>>        {
>>>                console.log("Exception caught");
>>>        }
>>>
>>> ...the catch() block never executes even when the console displays an
>>> error message.
>>>
>>> I do know that on an exception the callback function's argument is
>>> undefined.
>>>
>>> Thank You!
>>> Drew
>>>
>>> --
>>>
>>> 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<chromium-extensions%2bunsubscr...@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.


Reply via email to