Consolidate some of the throws

This commit is contained in:
Matt Nadareski
2020-09-15 17:09:35 -07:00
parent 74a0c47102
commit 044d70da6e
16 changed files with 58 additions and 175 deletions

View File

@@ -2283,9 +2283,6 @@ namespace SabreTools.Library.DatFiles
catch (IOException ex) catch (IOException ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return; return;
} }
} }

View File

@@ -1116,9 +1116,6 @@ namespace SabreTools.Library.DatItems
} }
catch (Exception ex) catch (Exception ex)
{ {
if (Globals.ThrowOnError)
throw ex;
// Absorb the error // Absorb the error
return 0; return 0;
} }

View File

@@ -127,9 +127,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return false; return false;
} }
@@ -208,9 +205,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return realentry; return realentry;
} }
@@ -250,9 +244,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return (ms, realentry); return (ms, realentry);
} }
@@ -390,9 +381,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
success = false; success = false;
} }
finally finally

View File

@@ -78,22 +78,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex) catch (EndOfStreamException ex)
{ {
// Catch this but don't count it as an error because SharpCompress is unsafe // Catch this but don't count it as an error because SharpCompress is unsafe
if (Globals.ThrowOnError) Globals.Logger.Verbose(ex);
throw ex;
} }
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {
if (Globals.ThrowOnError) Globals.Logger.Warning(ex);
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
@@ -181,9 +175,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
ms = null; ms = null;
realEntry = null; realEntry = null;
} }
@@ -253,9 +244,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return null; return null;
} }
} }

View File

@@ -71,22 +71,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex) catch (EndOfStreamException ex)
{ {
// Catch this but don't count it as an error because SharpCompress is unsafe // Catch this but don't count it as an error because SharpCompress is unsafe
if (Globals.ThrowOnError) Globals.Logger.Verbose(ex);
throw ex;
} }
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {
if (Globals.ThrowOnError) Globals.Logger.Warning(ex);
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
@@ -167,9 +161,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
ms = null; ms = null;
realEntry = null; realEntry = null;
} }
@@ -230,9 +221,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return null; return null;
} }
@@ -274,8 +262,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
} }
return empties; return empties;

View File

@@ -120,22 +120,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex) catch (EndOfStreamException ex)
{ {
// Catch this but don't count it as an error because SharpCompress is unsafe // Catch this but don't count it as an error because SharpCompress is unsafe
if (Globals.ThrowOnError) Globals.Logger.Verbose(ex);
throw ex;
} }
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {
if (Globals.ThrowOnError) Globals.Logger.Warning(ex);
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
@@ -251,9 +245,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
ms = null; ms = null;
realEntry = null; realEntry = null;
} }
@@ -341,9 +332,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return null; return null;
} }
@@ -397,8 +385,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
} }
return empties; return empties;
@@ -616,9 +602,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
success = false; success = false;
} }
finally finally
@@ -848,9 +831,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
success = false; success = false;
} }

View File

@@ -76,23 +76,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex) catch (EndOfStreamException ex)
{ {
// Catch this but don't count it as an error because SharpCompress is unsafe // Catch this but don't count it as an error because SharpCompress is unsafe
if (Globals.ThrowOnError) Globals.Logger.Verbose(ex);
throw ex;
} }
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {
if (Globals.ThrowOnError) Globals.Logger.Warning(ex);
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
@@ -173,9 +166,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
ms = null; ms = null;
realEntry = null; realEntry = null;
} }
@@ -236,9 +226,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return null; return null;
} }
@@ -280,8 +267,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
} }
return empties; return empties;
@@ -436,9 +421,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
success = false; success = false;
} }
finally finally
@@ -619,9 +601,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
success = false; success = false;
} }
finally finally

View File

@@ -72,22 +72,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex) catch (EndOfStreamException ex)
{ {
// Catch this but don't count it as an error because SharpCompress is unsafe // Catch this but don't count it as an error because SharpCompress is unsafe
if (Globals.ThrowOnError) Globals.Logger.Verbose(ex);
throw ex;
} }
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {
if (Globals.ThrowOnError) Globals.Logger.Warning(ex);
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
@@ -173,9 +167,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
ms = null; ms = null;
realEntry = null; realEntry = null;
} }
@@ -242,9 +233,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return null; return null;
} }
} }

View File

@@ -121,22 +121,16 @@ namespace SabreTools.Library.FileTypes
catch (EndOfStreamException ex) catch (EndOfStreamException ex)
{ {
// Catch this but don't count it as an error because SharpCompress is unsafe // Catch this but don't count it as an error because SharpCompress is unsafe
if (Globals.ThrowOnError) Globals.Logger.Verbose(ex);
throw ex;
} }
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {
if (Globals.ThrowOnError) Globals.Logger.Warning(ex);
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
encounteredErrors = true; encounteredErrors = true;
} }
@@ -252,9 +246,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
ms = null; ms = null;
realEntry = null; realEntry = null;
} }
@@ -346,9 +337,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return null; return null;
} }
@@ -402,8 +390,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
} }
return empties; return empties;
@@ -620,9 +606,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
success = false; success = false;
} }
finally finally
@@ -853,9 +836,6 @@ namespace SabreTools.Library.FileTypes
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
success = false; success = false;
} }

View File

@@ -99,10 +99,7 @@ namespace SabreTools.Library.Filtering
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Warning($"Exception found while parsing '{ini}': {ex}"); Globals.Logger.Warning(ex, $"Exception found while parsing '{ini}'");
if (Globals.ThrowOnError)
throw ex;
return false; return false;
} }

View File

@@ -92,9 +92,6 @@ namespace SabreTools.Library.IO
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex, $"An exception occurred getting the full path for '{input}'"); Globals.Logger.Error(ex, $"An exception occurred getting the full path for '{input}'");
if (Globals.ThrowOnError)
throw ex;
continue; continue;
} }
@@ -109,15 +106,11 @@ namespace SabreTools.Library.IO
} }
catch (PathTooLongException ex) catch (PathTooLongException ex)
{ {
Globals.Logger.Warning($"The path for '{dir}' was too long"); Globals.Logger.Warning(ex, $"The path for '{dir}' was too long");
if (Globals.ThrowOnError)
throw ex;
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex, $"An exception occurred processing '{dir}'"); Globals.Logger.Error(ex, $"An exception occurred processing '{dir}'");
if (Globals.ThrowOnError)
throw ex;
} }
} }
} }
@@ -195,9 +188,6 @@ namespace SabreTools.Library.IO
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex, $"An exception occurred getting the full path for '{input}'"); Globals.Logger.Error(ex, $"An exception occurred getting the full path for '{input}'");
if (Globals.ThrowOnError)
throw ex;
continue; continue;
} }
@@ -212,15 +202,11 @@ namespace SabreTools.Library.IO
} }
catch (PathTooLongException ex) catch (PathTooLongException ex)
{ {
Globals.Logger.Warning($"The path for '{file}' was too long"); Globals.Logger.Warning(ex, $"The path for '{file}' was too long");
if (Globals.ThrowOnError)
throw ex;
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex, $"An exception occurred processing '{file}'"); Globals.Logger.Error(ex, $"An exception occurred processing '{file}'");
if (Globals.ThrowOnError)
throw ex;
} }
} }
} }
@@ -232,15 +218,11 @@ namespace SabreTools.Library.IO
} }
catch (PathTooLongException ex) catch (PathTooLongException ex)
{ {
Globals.Logger.Warning($"The path for '{input}' was too long"); Globals.Logger.Warning(ex, $"The path for '{input}' was too long");
if (Globals.ThrowOnError)
throw ex;
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex, $"An exception occurred processing '{input}'"); Globals.Logger.Error(ex, $"An exception occurred processing '{input}'");
if (Globals.ThrowOnError)
throw ex;
} }
} }
} }

View File

@@ -189,9 +189,7 @@ namespace SabreTools.Library.IO
} }
catch (Exception ex) catch (Exception ex)
{ {
if (Globals.ThrowOnError) Globals.Logger.Warning(ex, $"An exception occurred trying to figure out the format of '{filename}'");
throw ex;
return 0; return 0;
} }
} }
@@ -303,9 +301,7 @@ namespace SabreTools.Library.IO
} }
catch (Exception ex) catch (Exception ex)
{ {
// Don't log file open errors Globals.Logger.Warning(ex, $"An exception occurred determining file type of '{input}'");
if (Globals.ThrowOnError)
throw ex;
} }
return outFileType; return outFileType;

View File

@@ -194,9 +194,7 @@ namespace SabreTools.Library.IO
} }
catch (IOException ex) catch (IOException ex)
{ {
if (Globals.ThrowOnError) Globals.Logger.Warning(ex, "An exception occurred during hashing.");
throw ex;
return new BaseFile(); return new BaseFile();
} }
finally finally
@@ -231,15 +229,11 @@ namespace SabreTools.Library.IO
} }
catch (NotSupportedException ex) catch (NotSupportedException ex)
{ {
Globals.Logger.Verbose("Stream does not support seeking to starting offset. Stream position not changed"); Globals.Logger.Verbose(ex, "Stream does not support seeking to starting offset. Stream position not changed");
if (Globals.ThrowOnError)
throw ex;
} }
catch (NotImplementedException ex) catch (NotImplementedException ex)
{ {
Globals.Logger.Warning("Stream does not support seeking to starting offset. Stream position not changed"); Globals.Logger.Warning(ex, "Stream does not support seeking to starting offset. Stream position not changed");
if (Globals.ThrowOnError)
throw ex;
} }
return -1; return -1;

View File

@@ -225,6 +225,21 @@ namespace SabreTools.Library.Logging
return true; return true;
} }
/// <summary>
/// Write the given exception as a verbose message to the log output
/// </summary>
/// <param name="ex">Exception to be written log</param>
/// <param name="output">String to be written log</param>
/// <param name="appendPrefix">True if the level and datetime should be prepended to each statement (default), false otherwise</param>
/// <returns>True if the output could be written, false otherwise</returns>
public bool Verbose(Exception ex, string output = null, bool appendPrefix = true)
{
if (Globals.ThrowOnError)
throw ex;
return Verbose($"{(output != null ? output + ": " : string.Empty)}{ex}", appendPrefix);
}
/// <summary> /// <summary>
/// Write the given string as a verbose message to the log output /// Write the given string as a verbose message to the log output
/// </summary> /// </summary>
@@ -236,6 +251,21 @@ namespace SabreTools.Library.Logging
return Log(output, LogLevel.VERBOSE, appendPrefix); return Log(output, LogLevel.VERBOSE, appendPrefix);
} }
/// <summary>
/// Write the given exception as a user message to the log output
/// </summary>
/// <param name="ex">Exception to be written log</param>
/// <param name="output">String to be written log</param>
/// <param name="appendPrefix">True if the level and datetime should be prepended to each statement (default), false otherwise</param>
/// <returns>True if the output could be written, false otherwise</returns>
public bool User(Exception ex, string output = null, bool appendPrefix = true)
{
if (Globals.ThrowOnError)
throw ex;
return User($"{(output != null ? output + ": " : string.Empty)}{ex}", appendPrefix);
}
/// <summary> /// <summary>
/// Write the given string as a user message to the log output /// Write the given string as a user message to the log output
/// </summary> /// </summary>
@@ -256,6 +286,9 @@ namespace SabreTools.Library.Logging
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public bool Warning(Exception ex, string output = null, bool appendPrefix = true) public bool Warning(Exception ex, string output = null, bool appendPrefix = true)
{ {
if (Globals.ThrowOnError)
throw ex;
return Warning($"{(output != null ? output + ": " : string.Empty)}{ex}", appendPrefix); return Warning($"{(output != null ? output + ": " : string.Empty)}{ex}", appendPrefix);
} }
@@ -280,6 +313,9 @@ namespace SabreTools.Library.Logging
/// <returns>True if the output could be written, false otherwise</returns> /// <returns>True if the output could be written, false otherwise</returns>
public bool Error(Exception ex, string output = null, bool appendPrefix = true) public bool Error(Exception ex, string output = null, bool appendPrefix = true)
{ {
if (Globals.ThrowOnError)
throw ex;
return Error($"{(output != null ? output + ": " : string.Empty)}{ex}", appendPrefix); return Error($"{(output != null ? output + ": " : string.Empty)}{ex}", appendPrefix);
} }

View File

@@ -202,9 +202,6 @@ namespace SabreTools.Library.Skippers
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
return false; return false;
} }
finally finally

View File

@@ -137,9 +137,7 @@ CREATE TABLE IF NOT EXISTS data (
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex); Globals.Logger.Error(ex);
if (Globals.ThrowOnError)
throw ex;
} }
finally finally
{ {