/// <summary> /// Creates a new <see cref="ErrorEncounteredEventArgs"/> to pass information around about when an error was encounted via a <see cref="ABSaveErrorHandler"/> /// </summary> public ErrorEncounteredEventArgs(ABSaveError error, int charLocation, string message = "") { // Set the error/location. Error = error; charLocation = Location; // Set the message. Message = message; }
/// <summary> /// Creates a new <see cref="ABSaveErrorHandler"/> which handles errors when serializing/parsing. /// </summary> /// <param name="suppressed">The errors to not cause an exception.</param> /// <param name="whenErrorEncountered">Code to run when an error is encountered.</param> /// <param name="ignoreAll">NOT RECOMMENDED: Ignore ALL errors and continue on as if nothing happened. (CAN CAUSE WEIRD RESULTS)</param> public ABSaveErrorHandler(ABSaveError suppressed, ErrorEncounteredEventHandler whenErrorEncountered = null, bool ignoreAll = false) { // Set the suppressed errors. SuppressedErrors = suppressed; // If the action isn't null, add it to the "ErrorEncountered" event. if (whenErrorEncountered != null) { ErrorEncountered += whenErrorEncountered; } // Set the "IgnoreAllErrors". IgnoreAllErrors = ignoreAll; }
/// <summary> /// Handles all the basic functionality for an error (throw exception if needed and run "ErrorEncountered"). /// </summary> /// <param name="args">The information about the error.</param> /// <param name="err">The type the error was.</param> /// <param name="exception">The actual exception this error is contained in.</param> internal void HandleError(ErrorEncounteredEventArgs args, ABSaveError err, Exception exception) { // Call the event "ErrorEncountered" - if we aren't meant to IgnoreAllErrors. if (!IgnoreAllErrors) { ErrorEncountered?.Invoke(args); } // If it isn't suppressed, throw an exception. if (!SuppressedErrors.HasFlag(err)) { throw exception; } }