Try catch and throw inside the method list()

24 views
Skip to first unread message

Guilherme Berghauser

unread,
Jan 17, 2014, 12:31:23 PM1/17/14
to persis...@googlegroups.com
I'm trying to use try and catch inside the callback method list(return) and it does not match the exception to catch up.

try{
 Entidy.all().list(return){
    try{
   ..
   ..
   }catch(e){
      throw e;
   }
} catch(e){
   alert(e.message);
}

The exception does not call alert.

Zef Hemel

unread,
Jan 19, 2014, 5:14:49 AM1/19/14
to persis...@googlegroups.com
This is because the function inside the list (syntax is really list(function(r) { ... })) is called asynchronously at a later time when execution has long left the try-catch block. This is why try-catch is so little used in async JS development.

-- Zef


--
You received this message because you are subscribed to the Google Groups "persistence.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to persistencej...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages