private T HandleEvaluationException <T>(Func <T> function) { try { return(function.Invoke()); } catch (Exception e) { if (e.InnerException?.Message != null) { throw new ExpressionEvaluationException(e.InnerException.Message); } var variables = _myInfo.GetReferencedVariables(); if (variables.Length != 0) { var exception = GetCustomExceptionMessage(variables); throw new ExpressionEvaluationException(exception); } throw new ExpressionEvaluationException(e.Message); } }