/// <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> /// Makes sure that a error handler isn't null, if it is create a new basic one with no suppression. /// </summary> /// <param name="errorHandler">The errorHandler that's been passed in - this is what gets checked.</param> /// <param name="whenErrorEncountered">Adds code to run when an error is thrown.</param> public static ABSaveErrorHandler EnsureNotNull(ABSaveErrorHandler errorHandler, ErrorEncounteredEventHandler whenErrorEncountered = null) { // If it's null, use a default one. if (errorHandler == null) { if (whenErrorEncountered == null) { return(Default); } else { return(new ABSaveErrorHandler(0, whenErrorEncountered)); } } else { // Otherwise, add the event to it and then return it. if (whenErrorEncountered != null) { errorHandler.ErrorEncountered += whenErrorEncountered; } return(errorHandler); } }