Don't use base Exception

This commit is contained in:
Oliver Booth 2022-11-30 18:47:57 +00:00
parent 80679fa8c4
commit 548a5de2be
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
4 changed files with 10 additions and 9 deletions

View File

@ -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))

View File

@ -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);

View File

@ -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!
};
}

View File

@ -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;