Divec has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/327143 )
Change subject: Use try-finally instead of try-catch-rethrow
......................................................................
Use try-finally instead of try-catch-rethrow
This works better with debuggers that break on uncaught exceptions
Change-Id: I28e4432ef83a6b7803d212575b43ad50344c78a2
---
M src/dm/ve.dm.TransactionProcessor.js
1 file changed, 18 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/43/327143/1
diff --git a/src/dm/ve.dm.TransactionProcessor.js
b/src/dm/ve.dm.TransactionProcessor.js
index b0db940..891e0db 100644
--- a/src/dm/ve.dm.TransactionProcessor.js
+++ b/src/dm/ve.dm.TransactionProcessor.js
@@ -84,7 +84,7 @@
* @param {Function} [presynchronizeHandler] Callback to emit before
synchronizing
*/
ve.dm.TransactionProcessor.prototype.process = function (
presynchronizeHandler ) {
- var op;
+ var op, completed;
// First process each operation to gather modifications in the
modification queue.
// If an exception occurs during this stage, we don't need to do
anything to recover,
@@ -98,30 +98,34 @@
// Apply the queued modifications
try {
+ completed = false;
this.applyModifications();
- } catch ( e ) {
- // Restore the linear model to its original state
- this.rollbackModifications();
- // Rethrow the exception
- throw e;
+ completed = true;
+ } finally {
+ if ( !completed ) {
+ // Restore the linear model to its original state
+ this.rollbackModifications();
+ }
}
// Mark the transaction as committed
this.transaction.markAsApplied();
// Synchronize the node tree for the modifications we just made
try {
+ completed = false;
if ( presynchronizeHandler ) {
presynchronizeHandler();
}
this.synchronizer.synchronize( this.transaction );
- } catch ( e ) {
- // Restore the linear model to its original state
- this.rollbackModifications();
- // The synchronizer may have left the tree in some sort of
weird half-baked state,
- // so rebuild it from scratch
- this.document.rebuildTree();
- // Rethrow the exception
- throw e;
+ completed = true;
+ } finally {
+ if ( !completed ) {
+ // Restore the linear model to its original state
+ this.rollbackModifications();
+ // The synchronizer may have left the tree in some sort
of weird half-baked state,
+ // so rebuild it from scratch
+ this.document.rebuildTree();
+ }
}
};
--
To view, visit https://gerrit.wikimedia.org/r/327143
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I28e4432ef83a6b7803d212575b43ad50344c78a2
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits