How can I create an expression that either throws an exception or returns a value based on a condition?
问题 I'm struggling to build an expression that if the condition is true throws an exception and if it's false that it should return a value but I'm always getting the ArgumentException : var expr = Expression.Condition( Expression.Equal(Expression.Constant(0), Expression.Constant(0)), Expression.Throw(Expression.Constant(new DivideByZeroException())), Expression.Constant(1)); var lambda = Expression.Lambda<Func<int>>(expr); var result = lambda.Compile()(); If I put Expression.Empty() as the third