Microsoft.Scripting.Actions.ErrorInfo.FromException C# (CSharp) Method

FromException() public static method

Creates a new ErrorInfo which represents an exception that should be thrown.
public static FromException ( Expression exceptionValue ) : ErrorInfo
exceptionValue System.Linq.Expressions.Expression
return ErrorInfo
        public static ErrorInfo FromException(Expression exceptionValue) {
            ContractUtils.RequiresNotNull(exceptionValue, "exceptionValue");
            ContractUtils.Requires(typeof(Exception).IsAssignableFrom(exceptionValue.Type), "exceptionValue", Strings.MustBeExceptionInstance);

            return new ErrorInfo(exceptionValue, ErrorInfoKind.Exception);
        }

Usage Example

Example #1
0
        private static ErrorInfo MakeIncorrectArgumentCountError(BindingTarget target)
        {
            int minArgs = Int32.MaxValue;
            int maxArgs = Int32.MinValue;

            foreach (int argCnt in target.ExpectedArgumentCount)
            {
                minArgs = System.Math.Min(minArgs, argCnt);
                maxArgs = System.Math.Max(maxArgs, argCnt);
            }

            return(ErrorInfo.FromException(
                       Ast.Call(
                           typeof(BinderOps).GetMethod("TypeErrorForIncorrectArgumentCount", new Type[] {
                typeof(string), typeof(int), typeof(int), typeof(int), typeof(int), typeof(bool), typeof(bool)
            }),
                           Ast.Constant(target.Name, typeof(string)), // name
                           Ast.Constant(minArgs),                     // min formal normal arg cnt
                           Ast.Constant(maxArgs),                     // max formal normal arg cnt
                           Ast.Constant(0),                           // default cnt
                           Ast.Constant(target.ActualArgumentCount),  // args provided
                           Ast.Constant(false),                       // hasArgList
                           Ast.Constant(false)                        // kwargs provided
                           )
                       ));
        }
All Usage Examples Of Microsoft.Scripting.Actions.ErrorInfo::FromException