@@ -41,18 +41,7 @@ public static void ExecuteInTransaction(this SQLiteDbConnection connection, Acti
4141 catch ( Exception ex )
4242 {
4343 Debug . Assert ( ex is OperationCanceledException || connection . AssertsDisabled , ex . GetType ( ) + ": " + ex . Message ) ;
44- if ( transaction . IsActive )
45- {
46- try
47- {
48- transaction . Rollback ( ) ;
49- }
50- catch ( Exception rollbackException )
51- {
52- Trace . WriteLine ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
53- Debug . Fail ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
54- }
55- }
44+ transaction . TryRollback ( ex ) ;
5645 throw ;
5746 }
5847 }
@@ -102,18 +91,7 @@ public static void ExecuteInTransaction<TState>(this SQLiteDbConnection connecti
10291 catch ( Exception ex )
10392 {
10493 Debug . Assert ( ex is OperationCanceledException || connection . AssertsDisabled , ex . GetType ( ) + ": " + ex . Message ) ;
105- if ( transaction . IsActive )
106- {
107- try
108- {
109- transaction . Rollback ( ) ;
110- }
111- catch ( Exception rollbackException )
112- {
113- Trace . WriteLine ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
114- Debug . Fail ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
115- }
116- }
94+ transaction . TryRollback ( ex ) ;
11795 throw ;
11896 }
11997 }
@@ -162,18 +140,7 @@ public static void ExecuteInTransaction(this SQLiteDbConnection connection, Isol
162140 catch ( Exception ex )
163141 {
164142 Debug . Assert ( ex is OperationCanceledException || connection . AssertsDisabled , ex . GetType ( ) + ": " + ex . Message ) ;
165- if ( transaction . IsActive )
166- {
167- try
168- {
169- transaction . Rollback ( ) ;
170- }
171- catch ( Exception rollbackException )
172- {
173- Trace . WriteLine ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
174- Debug . Fail ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
175- }
176- }
143+ transaction . TryRollback ( ex ) ;
177144 throw ;
178145 }
179146 }
@@ -224,18 +191,7 @@ public static void ExecuteInTransaction<TState>(this SQLiteDbConnection connecti
224191 catch ( Exception ex )
225192 {
226193 Debug . Assert ( ex is OperationCanceledException || connection . AssertsDisabled , ex . GetType ( ) + ": " + ex . Message ) ;
227- if ( transaction . IsActive )
228- {
229- try
230- {
231- transaction . Rollback ( ) ;
232- }
233- catch ( Exception rollbackException )
234- {
235- Trace . WriteLine ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
236- Debug . Fail ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
237- }
238- }
194+ transaction . TryRollback ( ex ) ;
239195 throw ;
240196 }
241197 }
@@ -285,18 +241,7 @@ public static T ExecuteInTransaction<T>(this SQLiteDbConnection connection, Func
285241 catch ( Exception ex )
286242 {
287243 Debug . Assert ( ex is OperationCanceledException || connection . AssertsDisabled , ex . GetType ( ) + ": " + ex . Message ) ;
288- if ( transaction . IsActive )
289- {
290- try
291- {
292- transaction . Rollback ( ) ;
293- }
294- catch ( Exception rollbackException )
295- {
296- Trace . WriteLine ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
297- Debug . Fail ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
298- }
299- }
244+ transaction . TryRollback ( ex ) ;
300245 throw ;
301246 }
302247 }
@@ -348,18 +293,7 @@ public static TResult ExecuteInTransaction<TState, TResult>(this SQLiteDbConnect
348293 catch ( Exception ex )
349294 {
350295 Debug . Assert ( ex is OperationCanceledException || connection . AssertsDisabled , ex . GetType ( ) + ": " + ex . Message ) ;
351- if ( transaction . IsActive )
352- {
353- try
354- {
355- transaction . Rollback ( ) ;
356- }
357- catch ( Exception rollbackException )
358- {
359- Trace . WriteLine ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
360- Debug . Fail ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
361- }
362- }
296+ transaction . TryRollback ( ex ) ;
363297 throw ;
364298 }
365299 }
@@ -410,18 +344,7 @@ public static T ExecuteInTransaction<T>(this SQLiteDbConnection connection, Isol
410344 catch ( Exception ex )
411345 {
412346 Debug . Assert ( ex is OperationCanceledException || connection . AssertsDisabled , ex . GetType ( ) + ": " + ex . Message ) ;
413- if ( transaction . IsActive )
414- {
415- try
416- {
417- transaction . Rollback ( ) ;
418- }
419- catch ( Exception rollbackException )
420- {
421- Trace . WriteLine ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
422- Debug . Fail ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
423- }
424- }
347+ transaction . TryRollback ( ex ) ;
425348 throw ;
426349 }
427350 }
@@ -474,18 +397,7 @@ public static TResult ExecuteInTransaction<TState, TResult>(this SQLiteDbConnect
474397 catch ( Exception ex )
475398 {
476399 Debug . Assert ( ex is OperationCanceledException || connection . AssertsDisabled , ex . GetType ( ) + ": " + ex . Message ) ;
477- if ( transaction . IsActive )
478- {
479- try
480- {
481- transaction . Rollback ( ) ;
482- }
483- catch ( Exception rollbackException )
484- {
485- Trace . WriteLine ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
486- Debug . Fail ( $ "SQLite transaction rollback failed: { rollbackException } ") ;
487- }
488- }
400+ transaction . TryRollback ( ex ) ;
489401 throw ;
490402 }
491403 }
0 commit comments