zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
459 stars 86 forks source link

Handling exceptions for ZExpression #107

Closed thomshib closed 3 years ago

thomshib commented 3 years ago

I have a Z expression Z.Expression.EvalContext.Compile<Func<TInput,TResult>>(string..) call. This compiled expression is invalid state .

How do I check for this error state so that I can handle it and throw a user defined exception?

JonathanMagnan commented 3 years ago

Hello @thomshib ,

We currently have an EvalException which can give you some information but it still doesn't support all cases. You still have to catch the general exception as well.

try
{
    var compile = Eval.Compile("1 * #2018-01-01#");
}
catch(EvalException evalException)
{
    var token = evalException.Token;
    var message = evalException.Message;
}
catch(Exception exception)
{
    var message = exception.Message;
}

Let me know if that answers your question.

Best Regards,

Jon

JonathanMagnan commented 3 years ago

Hello @thomshib ,

Since our last conversation, I haven't heard from you!

Let me know if you need more information or assistance about how to handle the exception.

Looking forward to hearing from you,

Jon

JonathanMagnan commented 3 years ago

Hello again @thomshib !

A simple reminder that we are here to assist you!

Don't hesitate to contact us if you need further assistance about how to handle the exception.

Best regards,

Jon