documentation wip
This commit is contained in:
40
MaybeError/Errors/Error.cs
Normal file
40
MaybeError/Errors/Error.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MaybeError.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// An information about an error that occured
|
||||
/// </summary>
|
||||
/// <param name="message">Message</param>
|
||||
/// <param name="details">Detailed information of the error</param>
|
||||
/// <param name="devDetails">Even more detailed information that is useful for logging</param>
|
||||
public class Error(string message, string? details = null, string? devDetails = null)
|
||||
{
|
||||
public readonly string Message = message;
|
||||
public readonly string? Details = details;
|
||||
public readonly string? DevDetails = devDetails;
|
||||
|
||||
public virtual Exception GetException()
|
||||
{
|
||||
return new Exception(Message);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
#if DEBUG
|
||||
return $"{Message}\n{Details}\n{DevDetails}";
|
||||
#else
|
||||
return $"{Message}\n{Details}";
|
||||
#endif
|
||||
}
|
||||
|
||||
public static implicit operator string(Error e)
|
||||
{
|
||||
return e.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
36
MaybeError/Errors/ExceptionError.cs
Normal file
36
MaybeError/Errors/ExceptionError.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace MaybeError.Errors;
|
||||
|
||||
public class ExceptionError : ExceptionError<Exception>
|
||||
{
|
||||
public ExceptionError(string message, Exception exception) : base(message, exception)
|
||||
{
|
||||
}
|
||||
public ExceptionError(Exception exception) : base(exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ExceptionError<T> : Error where T : Exception
|
||||
{
|
||||
public T Exception { get; set; }
|
||||
|
||||
public ExceptionError(string message, T exception) : base(message, exception.Message, exception.StackTrace)
|
||||
{
|
||||
Exception = exception;
|
||||
}
|
||||
|
||||
public ExceptionError(T exception) : base(exception.Message, devDetails: exception.StackTrace)
|
||||
{
|
||||
Exception = exception;
|
||||
}
|
||||
|
||||
public override T GetException()
|
||||
{
|
||||
return Exception;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Message}\n{Exception}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user