@@ -287,19 +287,17 @@ protected enum TryBlockEvaluatedState
287
287
{ ExpressionOperator . ConditionalAnd , ( dynamic left , dynamic right ) => {
288
288
if ( left is BubbleExceptionContainer leftExceptionContainer )
289
289
{
290
- ExceptionDispatchInfo . Capture ( leftExceptionContainer . Exception ) . Throw ( ) ;
291
- // Will not go here but need to return something to avoid compilation errors.
292
- return null ;
290
+ leftExceptionContainer . Throw ( ) ;
291
+ return null ; // this line is never reached
293
292
}
294
293
else if ( ! left )
295
294
{
296
295
return false ;
297
296
}
298
297
else if ( right is BubbleExceptionContainer rightExceptionContainer )
299
298
{
300
- ExceptionDispatchInfo . Capture ( rightExceptionContainer . Exception ) . Throw ( ) ;
301
- // Will not go here but need to return something to avoid compilation errors.
302
- return null ;
299
+ rightExceptionContainer . Throw ( ) ;
300
+ return null ; // this line is never reached
303
301
}
304
302
else
305
303
{
@@ -312,19 +310,17 @@ protected enum TryBlockEvaluatedState
312
310
{ ExpressionOperator . ConditionalOr , ( dynamic left , dynamic right ) => {
313
311
if ( left is BubbleExceptionContainer leftExceptionContainer )
314
312
{
315
- ExceptionDispatchInfo . Capture ( leftExceptionContainer . Exception ) . Throw ( ) ;
316
- // Will not go here but need to return something to avoid compilation errors.
317
- return null ;
313
+ leftExceptionContainer . Throw ( ) ;
314
+ return null ; // this line is never reached
318
315
}
319
316
else if ( left )
320
317
{
321
318
return true ;
322
319
}
323
320
else if ( right is BubbleExceptionContainer rightExceptionContainer )
324
321
{
325
- ExceptionDispatchInfo . Capture ( rightExceptionContainer . Exception ) . Throw ( ) ;
326
- // Will not go here but need to return something to avoid compilation errors.
327
- return null ;
322
+ rightExceptionContainer . Throw ( ) ;
323
+ return null ; // this line is never reached
328
324
}
329
325
else
330
326
{
@@ -2171,20 +2167,15 @@ where method.GetParameters()[0].ParameterType == objType // static extMethod(thi
2171
2167
}
2172
2168
catch ( NullReferenceException nullException )
2173
2169
{
2174
- stack . Push ( new BubbleExceptionContainer ( )
2175
- {
2176
- Exception = nullException
2177
- } ) ;
2170
+ stack . Push ( new BubbleExceptionContainer ( nullException ) ) ;
2178
2171
2179
2172
return true ;
2180
2173
}
2181
2174
catch ( Exception ex )
2182
2175
{
2183
2176
//Transport the exception in stack.
2184
- stack . Push ( new BubbleExceptionContainer ( )
2185
- {
2186
- Exception = new ExpressionEvaluatorSyntaxErrorException ( $ "The call of the method \" { varFuncName } \" on type [{ objType } ] generate this error : { ex . InnerException ? . Message ?? ex . Message } ", ex )
2187
- } ) ;
2177
+ var nestedException = new ExpressionEvaluatorSyntaxErrorException ( $ "The call of the method \" { varFuncName } \" on type [{ objType } ] generate this error : { ex . InnerException ? . Message ?? ex . Message } ", ex ) ;
2178
+ stack . Push ( new BubbleExceptionContainer ( nestedException ) ) ;
2188
2179
return true ; //Signals an error to the parsing method array call
2189
2180
}
2190
2181
}
@@ -2434,10 +2425,8 @@ where method.GetParameters()[0].ParameterType == objType // static extMethod(thi
2434
2425
catch ( Exception ex )
2435
2426
{
2436
2427
//Transport the exception in stack.
2437
- stack . Push ( new BubbleExceptionContainer ( )
2438
- {
2439
- Exception = new ExpressionEvaluatorSyntaxErrorException ( $ "[{ objType } ] object has no public Property or Member named \" { varFuncName } \" .", ex )
2440
- } ) ;
2428
+ var nestedException = new ExpressionEvaluatorSyntaxErrorException ( $ "[{ objType } ] object has no public Property or Member named \" { varFuncName } \" .", ex ) ;
2429
+ stack . Push ( new BubbleExceptionContainer ( nestedException ) ) ;
2441
2430
i -- ;
2442
2431
return true ; //Signals an error to the parsing method array call
2443
2432
}
@@ -3117,9 +3106,7 @@ protected virtual bool EvaluateString(string expression, Stack<object> stack, re
3117
3106
object obj = Evaluate ( innerExp . ToString ( ) ) ;
3118
3107
3119
3108
if ( obj is BubbleExceptionContainer bubbleExceptionContainer )
3120
- {
3121
- ExceptionDispatchInfo . Capture ( bubbleExceptionContainer . Exception ) . Throw ( ) ;
3122
- }
3109
+ bubbleExceptionContainer . Throw ( ) ;
3123
3110
3124
3111
resultString . Append ( obj ) ;
3125
3112
}
@@ -3218,7 +3205,7 @@ void EvaluateFirstNextUnaryOp(int j, ref int parentIndex)
3218
3205
}
3219
3206
else
3220
3207
{
3221
- list [ i ] = new BubbleExceptionContainer ( ) { Exception = ex } ; //Transport the processing error
3208
+ list [ i ] = new BubbleExceptionContainer ( ex ) ; //Transport the processing error
3222
3209
}
3223
3210
}
3224
3211
list . RemoveAt ( i - 1 ) ;
@@ -3253,7 +3240,7 @@ void EvaluateFirstPreviousUnaryOp(int j)
3253
3240
}
3254
3241
else
3255
3242
{
3256
- list [ i ] = new BubbleExceptionContainer ( ) { Exception = ex } ; //Transport the processing error
3243
+ list [ i ] = new BubbleExceptionContainer ( ex ) ; //Transport the processing error
3257
3244
}
3258
3245
}
3259
3246
list . RemoveAt ( i + 1 ) ;
@@ -3289,7 +3276,7 @@ void EvaluateFirstPreviousUnaryOp(int j)
3289
3276
}
3290
3277
else
3291
3278
{
3292
- list [ i ] = new BubbleExceptionContainer ( ) { Exception = ex } ; //Transport the processing error
3279
+ list [ i ] = new BubbleExceptionContainer ( ex ) ; //Transport the processing error
3293
3280
}
3294
3281
}
3295
3282
list . RemoveAt ( i + 1 ) ;
@@ -3314,16 +3301,15 @@ void EvaluateFirstPreviousUnaryOp(int j)
3314
3301
{
3315
3302
if ( item is BubbleExceptionContainer bubbleExceptionContainer )
3316
3303
{
3317
- //Throw the first occuring error
3318
- ExceptionDispatchInfo . Capture ( bubbleExceptionContainer . Exception ) . Throw ( ) ;
3304
+ bubbleExceptionContainer . Throw ( ) ; //Throw the first occuring error
3319
3305
}
3320
3306
}
3321
3307
throw new ExpressionEvaluatorSyntaxErrorException ( "Syntax error. Check that no operator is missing" ) ;
3322
3308
}
3323
3309
else if ( evaluationStackCount == 1 && stack . Peek ( ) is BubbleExceptionContainer bubbleExceptionContainer )
3324
3310
{
3325
3311
//We reached the top level of the evaluation. So we want to throw the resulting exception.
3326
- ExceptionDispatchInfo . Capture ( bubbleExceptionContainer . Exception ) . Throw ( ) ;
3312
+ bubbleExceptionContainer . Throw ( ) ;
3327
3313
}
3328
3314
3329
3315
return stack . Pop ( ) ;
@@ -3396,9 +3382,7 @@ protected virtual object ManageKindOfAssignation(string expression, ref int inde
3396
3382
}
3397
3383
3398
3384
if ( result is BubbleExceptionContainer exceptionContainer )
3399
- {
3400
- ExceptionDispatchInfo . Capture ( exceptionContainer . Exception ) . Throw ( ) ;
3401
- }
3385
+ exceptionContainer . Throw ( ) ;
3402
3386
3403
3387
if ( stack != null )
3404
3388
{
@@ -4757,7 +4741,14 @@ public partial class MethodsGroupEncaps
4757
4741
4758
4742
public partial class BubbleExceptionContainer
4759
4743
{
4760
- public Exception Exception { get ; set ; }
4744
+ public BubbleExceptionContainer ( Exception exception )
4745
+ {
4746
+ _dispatchInfo = ExceptionDispatchInfo . Capture ( exception ) ;
4747
+ }
4748
+
4749
+ private readonly ExceptionDispatchInfo _dispatchInfo ;
4750
+
4751
+ public void Throw ( ) => _dispatchInfo . Throw ( ) ;
4761
4752
}
4762
4753
4763
4754
public partial class ExpressionEvaluatorSyntaxErrorException : Exception
0 commit comments