@@ -287,19 +287,17 @@ protected enum TryBlockEvaluatedState
287287 { ExpressionOperator . ConditionalAnd , ( dynamic left , dynamic right ) => {
288288 if ( left is BubbleExceptionContainer leftExceptionContainer )
289289 {
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
293292 }
294293 else if ( ! left )
295294 {
296295 return false ;
297296 }
298297 else if ( right is BubbleExceptionContainer rightExceptionContainer )
299298 {
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
303301 }
304302 else
305303 {
@@ -312,19 +310,17 @@ protected enum TryBlockEvaluatedState
312310 { ExpressionOperator . ConditionalOr , ( dynamic left , dynamic right ) => {
313311 if ( left is BubbleExceptionContainer leftExceptionContainer )
314312 {
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
318315 }
319316 else if ( left )
320317 {
321318 return true ;
322319 }
323320 else if ( right is BubbleExceptionContainer rightExceptionContainer )
324321 {
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
328324 }
329325 else
330326 {
@@ -2171,20 +2167,15 @@ where method.GetParameters()[0].ParameterType == objType // static extMethod(thi
21712167 }
21722168 catch ( NullReferenceException nullException )
21732169 {
2174- stack . Push ( new BubbleExceptionContainer ( )
2175- {
2176- Exception = nullException
2177- } ) ;
2170+ stack . Push ( new BubbleExceptionContainer ( nullException ) ) ;
21782171
21792172 return true ;
21802173 }
21812174 catch ( Exception ex )
21822175 {
21832176 //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 ) ) ;
21882179 return true ; //Signals an error to the parsing method array call
21892180 }
21902181 }
@@ -2434,10 +2425,8 @@ where method.GetParameters()[0].ParameterType == objType // static extMethod(thi
24342425 catch ( Exception ex )
24352426 {
24362427 //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 ) ) ;
24412430 i -- ;
24422431 return true ; //Signals an error to the parsing method array call
24432432 }
@@ -3117,9 +3106,7 @@ protected virtual bool EvaluateString(string expression, Stack<object> stack, re
31173106 object obj = Evaluate ( innerExp . ToString ( ) ) ;
31183107
31193108 if ( obj is BubbleExceptionContainer bubbleExceptionContainer )
3120- {
3121- ExceptionDispatchInfo . Capture ( bubbleExceptionContainer . Exception ) . Throw ( ) ;
3122- }
3109+ bubbleExceptionContainer . Throw ( ) ;
31233110
31243111 resultString . Append ( obj ) ;
31253112 }
@@ -3218,7 +3205,7 @@ void EvaluateFirstNextUnaryOp(int j, ref int parentIndex)
32183205 }
32193206 else
32203207 {
3221- list [ i ] = new BubbleExceptionContainer ( ) { Exception = ex } ; //Transport the processing error
3208+ list [ i ] = new BubbleExceptionContainer ( ex ) ; //Transport the processing error
32223209 }
32233210 }
32243211 list . RemoveAt ( i - 1 ) ;
@@ -3253,7 +3240,7 @@ void EvaluateFirstPreviousUnaryOp(int j)
32533240 }
32543241 else
32553242 {
3256- list [ i ] = new BubbleExceptionContainer ( ) { Exception = ex } ; //Transport the processing error
3243+ list [ i ] = new BubbleExceptionContainer ( ex ) ; //Transport the processing error
32573244 }
32583245 }
32593246 list . RemoveAt ( i + 1 ) ;
@@ -3289,7 +3276,7 @@ void EvaluateFirstPreviousUnaryOp(int j)
32893276 }
32903277 else
32913278 {
3292- list [ i ] = new BubbleExceptionContainer ( ) { Exception = ex } ; //Transport the processing error
3279+ list [ i ] = new BubbleExceptionContainer ( ex ) ; //Transport the processing error
32933280 }
32943281 }
32953282 list . RemoveAt ( i + 1 ) ;
@@ -3314,16 +3301,15 @@ void EvaluateFirstPreviousUnaryOp(int j)
33143301 {
33153302 if ( item is BubbleExceptionContainer bubbleExceptionContainer )
33163303 {
3317- //Throw the first occuring error
3318- ExceptionDispatchInfo . Capture ( bubbleExceptionContainer . Exception ) . Throw ( ) ;
3304+ bubbleExceptionContainer . Throw ( ) ; //Throw the first occuring error
33193305 }
33203306 }
33213307 throw new ExpressionEvaluatorSyntaxErrorException ( "Syntax error. Check that no operator is missing" ) ;
33223308 }
33233309 else if ( evaluationStackCount == 1 && stack . Peek ( ) is BubbleExceptionContainer bubbleExceptionContainer )
33243310 {
33253311 //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 ( ) ;
33273313 }
33283314
33293315 return stack . Pop ( ) ;
@@ -3396,9 +3382,7 @@ protected virtual object ManageKindOfAssignation(string expression, ref int inde
33963382 }
33973383
33983384 if ( result is BubbleExceptionContainer exceptionContainer )
3399- {
3400- ExceptionDispatchInfo . Capture ( exceptionContainer . Exception ) . Throw ( ) ;
3401- }
3385+ exceptionContainer . Throw ( ) ;
34023386
34033387 if ( stack != null )
34043388 {
@@ -4757,7 +4741,14 @@ public partial class MethodsGroupEncaps
47574741
47584742 public partial class BubbleExceptionContainer
47594743 {
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 ( ) ;
47614752 }
47624753
47634754 public partial class ExpressionEvaluatorSyntaxErrorException : Exception
0 commit comments