1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-10 02:55:41 +00:00

Inherit exceptions from VirtualParadiseException

This commit is contained in:
Oliver Booth 2022-11-29 22:50:53 +00:00
parent c432437da7
commit 32bb9d92bb
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
5 changed files with 192 additions and 29 deletions

View File

@ -1,24 +1,39 @@
namespace VpSharp.Exceptions;
using VpSharp.Internal;
namespace VpSharp.Exceptions;
/// <summary>
/// The exception that is thrown when an operation was performed on an object that does not exist.
/// </summary>
public sealed class ObjectNotFoundException : Exception
public sealed class ObjectNotFoundException : VirtualParadiseException
{
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="ObjectNotFoundException" /> class.
/// </summary>
public ObjectNotFoundException()
: base(ReasonCode.ObjectNotFound)
{
}
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="ObjectNotFoundException" /> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public ObjectNotFoundException(string message)
: base(message)
: base(ReasonCode.ObjectNotFound, message)
{
}
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="ObjectNotFoundException" /> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner
/// exception is specified.
/// </param>
public ObjectNotFoundException(string message, Exception innerException)
: base(message, innerException)
: base(ReasonCode.ObjectNotFound, message, innerException)
{
}
}

View File

@ -1,24 +1,39 @@
namespace VpSharp.Exceptions;
using VpSharp.Internal;
namespace VpSharp.Exceptions;
/// <summary>
/// The exception that is thrown when a user could not be found.
/// </summary>
public sealed class UserNotFoundException : Exception
public sealed class UserNotFoundException : VirtualParadiseException
{
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="UserNotFoundException" /> class.
/// </summary>
public UserNotFoundException()
: base(ReasonCode.NoSuchUser)
{
}
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="UserNotFoundException" /> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public UserNotFoundException(string message)
: base(message)
: base(ReasonCode.NoSuchUser, message)
{
}
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="UserNotFoundException" /> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner
/// exception is specified.
/// </param>
public UserNotFoundException(string message, Exception innerException)
: base(message, innerException)
: base(ReasonCode.NoSuchUser, message, innerException)
{
}
}

View File

@ -1,25 +1,33 @@
namespace VpSharp.Exceptions;
using VpSharp.Internal;
namespace VpSharp.Exceptions;
/// <summary>
/// The exception that is thrown when the version of the .NET wrapper and the version of the native SDK do not match.
/// </summary>
public sealed class VersionMismatchException : Exception
public sealed class VersionMismatchException : VirtualParadiseException
{
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="VersionMismatchException" /> class.
/// </summary>
public VersionMismatchException()
: this("The version of the .NET wrapper and the version of the native SDK do not match.")
{
}
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="VersionMismatchException" /> class.
/// </summary>
public VersionMismatchException(string message)
: base(message)
: base(ReasonCode.VersionMismatch, message)
{
}
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="VersionMismatchException" /> class.
/// </summary>
public VersionMismatchException(string message, Exception innerException)
: base(message, innerException)
: base(ReasonCode.VersionMismatch, message, innerException)
{
}
}

View File

@ -0,0 +1,78 @@
using VpSharp.Internal;
namespace VpSharp.Exceptions;
/// <summary>
/// The exception that is thrown when an operation fails in the native SDK.
/// </summary>
public class VirtualParadiseException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="VirtualParadiseException" /> class.
/// </summary>
public VirtualParadiseException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="VirtualParadiseException" /> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public VirtualParadiseException(string message)
: base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="VirtualParadiseException" /> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner
/// exception is specified.
/// </param>
public VirtualParadiseException(string message, Exception innerException) : base(message, innerException)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="VirtualParadiseException" /> class.
/// </summary>
/// <param name="reasonCode">The underlying reason code.</param>
internal VirtualParadiseException(ReasonCode reasonCode)
{
ReasonCode = reasonCode;
}
/// <summary>
/// Initializes a new instance of the <see cref="VirtualParadiseException" /> class.
/// </summary>
/// <param name="reasonCode">The underlying reason code.</param>
/// <param name="message">The message that describes the error.</param>
internal VirtualParadiseException(ReasonCode reasonCode, string message)
: base(message)
{
ReasonCode = reasonCode;
}
/// <summary>
/// Initializes a new instance of the <see cref="VirtualParadiseException" /> class.
/// </summary>
/// <param name="reasonCode">The underlying reason code.</param>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner
/// exception is specified.
/// </param>
internal VirtualParadiseException(ReasonCode reasonCode, string message, Exception innerException)
: base(message, innerException)
{
ReasonCode = reasonCode;
}
/// <summary>
/// Gets the reason code.
/// </summary>
/// <value>The reason code.</value>
internal ReasonCode ReasonCode { get; }
}

View File

@ -1,24 +1,71 @@
namespace VpSharp.Exceptions;
using VpSharp.Internal;
namespace VpSharp.Exceptions;
/// <summary>
/// The exception that is thrown when an attempt to access a world does not exist.
/// </summary>
public sealed class WorldNotFoundException : Exception
public sealed class WorldNotFoundException : VirtualParadiseException
{
/// <inheritdoc />
public WorldNotFoundException()
/// <summary>
/// Initializes a new instance of the <see cref="WorldNotFoundException" /> class.
/// </summary>
public WorldNotFoundException() : base(ReasonCode.WorldNotFound)
{
WorldName = string.Empty;
}
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="WorldNotFoundException" /> class.
/// </summary>
/// <param name="worldName">The name of the world that wasn't found.</param>
public WorldNotFoundException(string worldName)
: base($"No world with the name {worldName} was found.")
: this(worldName, $"No world with the name {worldName} was found.")
{
}
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="WorldNotFoundException" /> class.
/// </summary>
/// <param name="worldName">The name of the world that wasn't found.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner
/// exception is specified.
/// </param>
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)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="WorldNotFoundException" /> class.
/// </summary>
/// <param name="worldName">The name of the world that wasn't found.</param>
/// <param name="message">The message that describes the error.</param>
public WorldNotFoundException(string worldName, string message)
: base(ReasonCode.WorldNotFound, message)
{
WorldName = worldName;
}
/// <summary>
/// Initializes a new instance of the <see cref="WorldNotFoundException" /> class.
/// </summary>
/// <param name="worldName">The name of the world that wasn't found.</param>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">
/// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner
/// exception is specified.
/// </param>
public WorldNotFoundException(string worldName, string message, Exception innerException)
: base(ReasonCode.WorldNotFound, message, innerException)
{
WorldName = worldName;
}
/// <summary>
/// Gets the name of the world that wasn't found.
/// </summary>
/// <value>The name of the world that wasn't found.</value>
public string WorldName { get; }
}