Provides data for a record parsing error event.
Inheritance: System.EventArgs
Example #1
0
        protected virtual void OnParseError(ParseErrorEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            this.ParseError?.Invoke(this, e);
        }
Example #2
0
        /// <summary>
        /// Handles a parsing error.
        /// </summary>
        /// <param name="error">The parsing error that occurred.</param>
        /// <exception cref="ArgumentNullException">
        ///	<paramref name="error"/> is <c>null</c>.
        /// </exception>
        protected void HandleParseError(MalformedRecordException error)
        {
            if (error == null)
            {
                throw new ArgumentNullException(nameof(error));
            }

            switch (this.ParseErrorAction)
            {
            case ParseErrorAction.ThrowException:
                throw error;

            case ParseErrorAction.RaiseEvent:
                ParseErrorEventArgs e = new ParseErrorEventArgs(error, ParseErrorAction.ThrowException);
                OnParseError(e);

                switch (e.Action)
                {
                case ParseErrorAction.ThrowException:
                    throw e.Error;

                case ParseErrorAction.RaiseEvent:
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionMessages.IO_ParseErrorActionInvalidInsideParseErrorEvent, e.Action), e.Error);

                case ParseErrorAction.SkipToNextLine:
                    SkipToNextLine();
                    break;

                default:
                    throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionMessages.IO_ParseErrorActionNotSupported, e.Action), e.Error);
                }
                break;

            case ParseErrorAction.SkipToNextLine:
                SkipToNextLine();
                break;

            default:
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.ExceptionMessages.IO_ParseErrorActionNotSupported, this.ParseErrorAction), error);
            }
        }