Skip to content

Commit 2b6408d

Browse files
committed
处理抛出异常的返回值
1 parent c532987 commit 2b6408d

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/MediaConverters/MediaConverters.Tool/Contexts/MediaConverterErrorCode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public readonly record struct MediaConverterErrorCode
4040

4141
public static readonly ErrorCode GdiException = new(1005, "Gdi exception");
4242

43+
public static readonly ErrorCode UnknownException = new(1006, "Unknown exception");
44+
4345
/// <summary>
4446
/// 错误代码
4547
/// </summary>

src/MediaConverters/MediaConverters.Tool/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ internal static async Task<ErrorCode> RunAsync(Options options)
8787
var errorMessage = $"Failed to convert image file '{inputFile.FullName}'. Reason: {imageFileOptimizationResult.FailureReason}";
8888
if (imageFileOptimizationResult.Exception is { } exception)
8989
{
90-
errorMessage += $" Exception: {exception}";
90+
errorMessage += $". Exception: {exception}";
9191
}
9292

9393
Console.Error.WriteLine(errorMessage);
94-
94+
9595
switch (imageFileOptimizationResult.FailureReason)
9696
{
9797
case ImageFileOptimizationFailureReason.Ok:
@@ -107,8 +107,10 @@ internal static async Task<ErrorCode> RunAsync(Options options)
107107
return ErrorCode.NotSupported;
108108
case ImageFileOptimizationFailureReason.GdiException:
109109
return ErrorCode.GdiException;
110+
case ImageFileOptimizationFailureReason.Exception:
111+
return ErrorCode.UnknownException;
110112
default:
111-
throw new ArgumentOutOfRangeException();
113+
throw new ArgumentOutOfRangeException($"Unknown FailureReason. FailureReason={imageFileOptimizationResult.FailureReason}");
112114
}
113115

114116
return ErrorCode.UnknownError;

0 commit comments

Comments
 (0)