Repository navigation
How can we return error value from ReflectionFunction? #925
Answered
by
anderson-joyle
Y.Sakamoto (exceedsystem)
asked this question in
Q&A
|
Is there a way to return an error from a custom function that returns such as a StringValue? Example: using Microsoft.PowerFx;
using Microsoft.PowerFx.Types;
var config = new PowerFxConfig();
config.AddFunction(new MyFuncFunction());
var engine = new RecalcEngine(config);
var ret = engine.Eval("If(IsError(MyFunc(\"\")), \"Error\", \"Success\")");
public class MyFuncFunction : ReflectionFunction
{
public StringValue Execute(StringValue param)
{
if (param.Value == "")
{
// Failed
// How to return error from here?
}
else
{
// Success
return FormulaValue.New("");
}
}
}Best regards. |
Answered by
anderson-joyle
Dec 20, 2022
Replies: 2 comments 5 replies
|
Check the CommomErrors class. You can call some of the static methods to get a pre-built error message or you can call As a reminder, it is also possible to create a ErrorValue from an expression: |
5 replies
Answer selected by
anderson-joyle
|
FYI - here's an improvement here: #1018 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check the CommomErrors class. You can call some of the static methods to get a pre-built error message or you can call
CommomErrors.CustomErrorto build your own custom error message.If none of them work for you, it is still a good source to learn how to build ErrorValue objects.
As a reminder, it is also possible to create a ErrorValue from an expression:
Error({Kind:ErrorKind.InvalidArgument, Message:"This argument is invalid."})