From 32bb9d92bb04b4581e8ebe38c4198aa8fb44d948 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 29 Nov 2022 22:50:53 +0000 Subject: [PATCH] Inherit exceptions from VirtualParadiseException --- .../src/Exceptions/ObjectNotFoundException.cs | 29 +++++-- .../src/Exceptions/UserNotFoundException.cs | 29 +++++-- .../Exceptions/VersionMismatchException.cs | 22 ++++-- .../Exceptions/VirtualParadiseException.cs | 78 +++++++++++++++++++ .../src/Exceptions/WorldNotFoundException.cs | 63 +++++++++++++-- 5 files changed, 192 insertions(+), 29 deletions(-) create mode 100644 VpSharp/src/Exceptions/VirtualParadiseException.cs diff --git a/VpSharp/src/Exceptions/ObjectNotFoundException.cs b/VpSharp/src/Exceptions/ObjectNotFoundException.cs index e5c4086..8fefe6c 100644 --- a/VpSharp/src/Exceptions/ObjectNotFoundException.cs +++ b/VpSharp/src/Exceptions/ObjectNotFoundException.cs @@ -1,24 +1,39 @@ -namespace VpSharp.Exceptions; +using VpSharp.Internal; + +namespace VpSharp.Exceptions; /// /// The exception that is thrown when an operation was performed on an object that does not exist. /// -public sealed class ObjectNotFoundException : Exception +public sealed class ObjectNotFoundException : VirtualParadiseException { - /// + /// + /// Initializes a new instance of the class. + /// public ObjectNotFoundException() + : base(ReasonCode.ObjectNotFound) { } - /// + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public ObjectNotFoundException(string message) - : base(message) + : base(ReasonCode.ObjectNotFound, message) { } - /// + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + /// + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner + /// exception is specified. + /// public ObjectNotFoundException(string message, Exception innerException) - : base(message, innerException) + : base(ReasonCode.ObjectNotFound, message, innerException) { } } diff --git a/VpSharp/src/Exceptions/UserNotFoundException.cs b/VpSharp/src/Exceptions/UserNotFoundException.cs index efaa9a5..3d96cda 100644 --- a/VpSharp/src/Exceptions/UserNotFoundException.cs +++ b/VpSharp/src/Exceptions/UserNotFoundException.cs @@ -1,24 +1,39 @@ -namespace VpSharp.Exceptions; +using VpSharp.Internal; + +namespace VpSharp.Exceptions; /// /// The exception that is thrown when a user could not be found. /// -public sealed class UserNotFoundException : Exception +public sealed class UserNotFoundException : VirtualParadiseException { - /// + /// + /// Initializes a new instance of the class. + /// public UserNotFoundException() + : base(ReasonCode.NoSuchUser) { } - /// + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. public UserNotFoundException(string message) - : base(message) + : base(ReasonCode.NoSuchUser, message) { } - /// + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + /// + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner + /// exception is specified. + /// public UserNotFoundException(string message, Exception innerException) - : base(message, innerException) + : base(ReasonCode.NoSuchUser, message, innerException) { } } diff --git a/VpSharp/src/Exceptions/VersionMismatchException.cs b/VpSharp/src/Exceptions/VersionMismatchException.cs index 583340b..afd2541 100644 --- a/VpSharp/src/Exceptions/VersionMismatchException.cs +++ b/VpSharp/src/Exceptions/VersionMismatchException.cs @@ -1,25 +1,33 @@ -namespace VpSharp.Exceptions; +using VpSharp.Internal; + +namespace VpSharp.Exceptions; /// /// The exception that is thrown when the version of the .NET wrapper and the version of the native SDK do not match. /// -public sealed class VersionMismatchException : Exception +public sealed class VersionMismatchException : VirtualParadiseException { - /// + /// + /// Initializes a new instance of the class. + /// public VersionMismatchException() : this("The version of the .NET wrapper and the version of the native SDK do not match.") { } - /// + /// + /// Initializes a new instance of the class. + /// public VersionMismatchException(string message) - : base(message) + : base(ReasonCode.VersionMismatch, message) { } - /// + /// + /// Initializes a new instance of the class. + /// public VersionMismatchException(string message, Exception innerException) - : base(message, innerException) + : base(ReasonCode.VersionMismatch, message, innerException) { } } diff --git a/VpSharp/src/Exceptions/VirtualParadiseException.cs b/VpSharp/src/Exceptions/VirtualParadiseException.cs new file mode 100644 index 0000000..9ce062e --- /dev/null +++ b/VpSharp/src/Exceptions/VirtualParadiseException.cs @@ -0,0 +1,78 @@ +using VpSharp.Internal; + +namespace VpSharp.Exceptions; + +/// +/// The exception that is thrown when an operation fails in the native SDK. +/// +public class VirtualParadiseException : Exception +{ + /// + /// Initializes a new instance of the class. + /// + public VirtualParadiseException() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public VirtualParadiseException(string message) + : base(message) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + /// + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner + /// exception is specified. + /// + public VirtualParadiseException(string message, Exception innerException) : base(message, innerException) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The underlying reason code. + internal VirtualParadiseException(ReasonCode reasonCode) + { + ReasonCode = reasonCode; + } + + /// + /// Initializes a new instance of the class. + /// + /// The underlying reason code. + /// The message that describes the error. + internal VirtualParadiseException(ReasonCode reasonCode, string message) + : base(message) + { + ReasonCode = reasonCode; + } + + /// + /// Initializes a new instance of the class. + /// + /// The underlying reason code. + /// The message that describes the error. + /// + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner + /// exception is specified. + /// + internal VirtualParadiseException(ReasonCode reasonCode, string message, Exception innerException) + : base(message, innerException) + { + ReasonCode = reasonCode; + } + + /// + /// Gets the reason code. + /// + /// The reason code. + internal ReasonCode ReasonCode { get; } +} diff --git a/VpSharp/src/Exceptions/WorldNotFoundException.cs b/VpSharp/src/Exceptions/WorldNotFoundException.cs index 4c12203..c966939 100644 --- a/VpSharp/src/Exceptions/WorldNotFoundException.cs +++ b/VpSharp/src/Exceptions/WorldNotFoundException.cs @@ -1,24 +1,71 @@ -namespace VpSharp.Exceptions; +using VpSharp.Internal; + +namespace VpSharp.Exceptions; /// /// The exception that is thrown when an attempt to access a world does not exist. /// -public sealed class WorldNotFoundException : Exception +public sealed class WorldNotFoundException : VirtualParadiseException { - /// - public WorldNotFoundException() + /// + /// Initializes a new instance of the class. + /// + public WorldNotFoundException() : base(ReasonCode.WorldNotFound) { + WorldName = string.Empty; } - /// + /// + /// Initializes a new instance of the class. + /// + /// The name of the world that wasn't found. public WorldNotFoundException(string worldName) - : base($"No world with the name {worldName} was found.") + : this(worldName, $"No world with the name {worldName} was found.") { } - /// + /// + /// Initializes a new instance of the class. + /// + /// The name of the world that wasn't found. + /// + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner + /// exception is specified. + /// public WorldNotFoundException(string worldName, Exception innerException) - : base($"No world with the name {worldName} was found.", innerException) + : this(worldName, $"No world with the name {worldName} was found.", innerException) { } + + /// + /// Initializes a new instance of the class. + /// + /// The name of the world that wasn't found. + /// The message that describes the error. + public WorldNotFoundException(string worldName, string message) + : base(ReasonCode.WorldNotFound, message) + { + WorldName = worldName; + } + + /// + /// Initializes a new instance of the class. + /// + /// The name of the world that wasn't found. + /// The message that describes the error. + /// + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner + /// exception is specified. + /// + public WorldNotFoundException(string worldName, string message, Exception innerException) + : base(ReasonCode.WorldNotFound, message, innerException) + { + WorldName = worldName; + } + + /// + /// Gets the name of the world that wasn't found. + /// + /// The name of the world that wasn't found. + public string WorldName { get; } }