using System; using System.Runtime.Serialization; using UnityEngine.ResourceManagement.ResourceLocations; using UnityEngine.ResourceManagement.Util; namespace UnityEngine.ResourceManagement.Exceptions { /// /// Base class for all ResourceManager related exceptions. /// public class ResourceManagerException : Exception { /// /// Construct a new ResourceManagerException. /// public ResourceManagerException() { } /// /// Construct a new ResourceManagerException. /// /// Message to describe the exception. public ResourceManagerException(string message) : base(message) { } /// /// Construct a new ResourceManagerException. /// /// Message to describe the exception. /// Inner exception that caused this exception. public ResourceManagerException(string message, Exception innerException) : base(message, innerException) { } /// /// Construct a new ResourceManagerException. /// /// Message to describe the exception. /// Context related to the exception. protected ResourceManagerException(SerializationInfo message, StreamingContext context) : base(message, context) { } /// Provides a new string object describing the exception. /// A newly allocated managed string. public override string ToString() => $"{GetType().Name} : {base.Message}\n{InnerException}"; } /// /// Exception returned when the IResourceProvider is not found for a location. /// public class UnknownResourceProviderException : ResourceManagerException { /// /// The location that contains the provider id that was not found. /// public IResourceLocation Location { get; private set; } /// /// Construct a new UnknownResourceProviderException /// /// The location that caused the exception to be created. public UnknownResourceProviderException(IResourceLocation location) { Location = location; } /// /// Construct a new UnknownResourceProviderException /// public UnknownResourceProviderException() { } /// /// Construct a new UnknownResourceProviderException /// /// Message to describe the exception. public UnknownResourceProviderException(string message) : base(message) { } /// /// Construct a new UnknownResourceProviderException /// /// Message to describe the exception. /// Inner exception that caused this exception. public UnknownResourceProviderException(string message, Exception innerException) : base(message, innerException) { } /// /// Construct a new UnknownResourceProviderException /// /// Message to describe the exception. /// Context related to the exception. protected UnknownResourceProviderException(SerializationInfo message, StreamingContext context) : base(message, context) { } /// /// Returns a string describing this exception. /// public override string Message { get { return base.Message + ", ProviderId=" + Location.ProviderId + ", Location=" + Location; } } /// /// Returns string representation of exception. /// /// String representation of exception. public override string ToString() { return Message; } } /// /// Class that represent an error that occured during an AsyncOperation. /// public class OperationException : Exception { /// /// Creates a new instance of . /// /// A message describing the error. /// The exception that caused the error, if any. public OperationException(string message, Exception innerException = null) : base(message, innerException) { } /// Provides a new string object describing the exception. /// A newly allocated managed string. public override string ToString() => $"{GetType().Name} : {base.Message}\n{InnerException}"; } /// /// Class that represent an error that occured during a ProviderOperation. /// public class ProviderException : OperationException { /// /// Creates a new instance of . /// /// A message describing the error. /// The resource location that the operation was trying to provide. /// The exception that caused the error, if any. public ProviderException(string message, IResourceLocation location = null, Exception innerException = null) : base(message, innerException) { Location = location; } /// /// The resource location that the operation was trying to provide. /// public IResourceLocation Location { get; } } /// /// Class representing an error occured during an operation that remotely fetch data. /// public class RemoteProviderException : ProviderException { /// /// Creates a new instance of . /// /// A message describing the error. /// The resource location that the operation was trying to provide. /// The result of the unity web request, if any. /// The exception that caused the error, if any. public RemoteProviderException(string message, IResourceLocation location = null, UnityWebRequestResult uwrResult = null, Exception innerException = null) : base(message, location, innerException) { WebRequestResult = uwrResult; } /// /// Returns a string describing this exception. /// public override string Message => this.ToString(); /// /// The result of the unity web request, if any. /// public UnityWebRequestResult WebRequestResult { get; } /// Provides a new string object describing the exception. /// A newly allocated managed string. public override string ToString() { if (WebRequestResult != null) return $"{GetType().Name} : {base.Message}\nUnityWebRequest result : {WebRequestResult}\n{InnerException}"; else return base.ToString(); } } }