From 548a5de2be7ebfbe24dd492d6ced24d86563dfca Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 30 Nov 2022 18:47:57 +0000 Subject: [PATCH] Don't use base Exception --- VpSharp.Commands/CommandsExtension.cs | 3 +-- VpSharp/src/VirtualParadiseClient.Extensions.cs | 3 +-- VpSharp/src/VirtualParadiseClient.Objects.cs | 8 +++++--- VpSharp/src/VirtualParadiseClient.cs | 5 +++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/VpSharp.Commands/CommandsExtension.cs b/VpSharp.Commands/CommandsExtension.cs index 0b1ebbf..cec8a2f 100644 --- a/VpSharp.Commands/CommandsExtension.cs +++ b/VpSharp.Commands/CommandsExtension.cs @@ -120,8 +120,7 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension if (Activator.CreateInstance(moduleType) is not CommandModule module) { - var innerException = new Exception($"Could not instantiate {moduleType.FullName}"); - throw new TypeInitializationException(moduleType.FullName, innerException); + throw new TypeInitializationException(moduleType.FullName, null); } foreach (MethodInfo method in moduleType.GetMethods(BindingFlags)) diff --git a/VpSharp/src/VirtualParadiseClient.Extensions.cs b/VpSharp/src/VirtualParadiseClient.Extensions.cs index 918cf55..7f5a6eb 100644 --- a/VpSharp/src/VirtualParadiseClient.Extensions.cs +++ b/VpSharp/src/VirtualParadiseClient.Extensions.cs @@ -68,8 +68,7 @@ public sealed partial class VirtualParadiseClient object? instance = Activator.CreateInstance(type, bindingFlags, null, argumentsActual, CultureInfo.InvariantCulture); if (instance is not VirtualParadiseClientExtension extension) { - var innerException = new Exception($"Could not instantiate {type}"); - throw new TypeInitializationException(type.FullName, innerException); + throw new TypeInitializationException(type.FullName, null); } _extensions.Add(extension); diff --git a/VpSharp/src/VirtualParadiseClient.Objects.cs b/VpSharp/src/VirtualParadiseClient.Objects.cs index 7e71b5e..4ca02a6 100644 --- a/VpSharp/src/VirtualParadiseClient.Objects.cs +++ b/VpSharp/src/VirtualParadiseClient.Objects.cs @@ -125,10 +125,12 @@ public sealed partial class VirtualParadiseClient PreReturn: return reason switch { - ReasonCode.DatabaseError => throw new Exception("Error communicating with the database."), + ReasonCode.DatabaseError => + throw new VirtualParadiseException(ReasonCode.DatabaseError, "Error communicating with the database."), ReasonCode.ObjectNotFound => throw new ObjectNotFoundException(), - ReasonCode.UnknownError => throw new Exception("An unknown error occurred retrieving the object."), - _ when reason != ReasonCode.Success => throw new Exception($"{reason:D} ({reason:G})"), + ReasonCode.UnknownError => + throw new VirtualParadiseException(ReasonCode.UnknownError, "An unknown error occurred retrieving the object."), + _ when reason != ReasonCode.Success => throw new VirtualParadiseException(reason, $"{reason:D} ({reason:G})"), _ => virtualParadiseObject! }; } diff --git a/VpSharp/src/VirtualParadiseClient.cs b/VpSharp/src/VirtualParadiseClient.cs index 69ea777..fa9857c 100644 --- a/VpSharp/src/VirtualParadiseClient.cs +++ b/VpSharp/src/VirtualParadiseClient.cs @@ -334,7 +334,8 @@ public sealed partial class VirtualParadiseClient : IDisposable case ReasonCode.ConnectionError: case ReasonCode.WorldLoginError: - throw new Exception("Connection to the universe server was lost, or connecting to the world failed."); + throw new VirtualParadiseException(reason, + "Connection to the universe server was lost, or connecting to the world failed."); case ReasonCode.WorldNotFound: throw new WorldNotFoundException(worldName); @@ -343,7 +344,7 @@ public sealed partial class VirtualParadiseClient : IDisposable throw new TimeoutException("Connection to the world server timed out."); default: - throw new Exception($"Unknown error: {reason:D} ({reason:G})"); + throw new VirtualParadiseException(reason, $"Unknown error: {reason:D} ({reason:G})"); } int size;