Try-Catch block scope and callback.

32 views
Skip to first unread message

Jane Chen

unread,
Oct 24, 2016, 3:36:06 AM10/24/16
to v8-users
Embedding v8 5.3.  In my embedding application, the user can make some updates and the updates are committed as one transaction when the script exits.  When one statement throws an error which is caught by a try-catch block, the scope of the try-catch block determines the aborted changes.  Here's an example:

try {
  update1();
  update2();
catch(err) {}

In the above example, if update2 throws an exception, the changes made by update1 should be aborted.

In contrast, in the following script, if update2 throws an exception, the changes made by update1 should be committed:

update1();
try {
  update2();
catch(err) {}

Does v8 provide any way to register for user-specified try-catch blocks for embedders to handle this use case?  I tried TryCatch.SetVerbose, but apparently it's not meant for this.

Thanks in advance.


Ben Noordhuis

unread,
Oct 24, 2016, 6:50:35 AM10/24/16
to v8-users
You could use the debugger to break on caught and/or uncaught
exceptions. It has some overhead but you would have to benchmark it
if you want to know exactly how much.

The debugger API is getting an overhaul (it's being replaced by the V8
inspector) so you may have to rework some of your code when you
upgrade.

Yang Guo

unread,
Oct 28, 2016, 1:18:28 AM10/28/16
to v8-users
This is not how Javascript works. There is no way to stage changes and only later commit them. Try-catch is not a transactional block.
Reply all
Reply to author
Forward
0 new messages