custom exceptions, methods to create modules and states of specific type from generic ones
This commit is contained in:
21
Assets/Engine/Runtime/Utilities/Exceptions.cs
Normal file
21
Assets/Engine/Runtime/Utilities/Exceptions.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Utilities
|
||||
{
|
||||
public class EngineException : Exception
|
||||
{
|
||||
public EngineException(string message) : base($"<b>[EngineException]</b> {message}") {}
|
||||
}
|
||||
|
||||
public class WrongTypeException : EngineException
|
||||
{
|
||||
public WrongTypeException(Type expected, Type found, Type baseType) : base($"Wrong type of {baseType} ({found} instead of {expected})") {}
|
||||
|
||||
public WrongTypeException(string message) : base(message) {}
|
||||
}
|
||||
|
||||
public class OptionException : Exception
|
||||
{
|
||||
public OptionException(string message) : base(message) {}
|
||||
}
|
||||
}
|
||||
3
Assets/Engine/Runtime/Utilities/Exceptions.cs.meta
Normal file
3
Assets/Engine/Runtime/Utilities/Exceptions.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e84dc071915b429ba633c9541d3411ac
|
||||
timeCreated: 1668964775
|
||||
@@ -49,8 +49,8 @@ namespace EscapeRoomEngine.Engine.Runtime.Utilities
|
||||
{
|
||||
public bool IsSome() => false;
|
||||
public bool IsNone() => true;
|
||||
public T Expect(string message) => throw new Exception(message);
|
||||
public T Unwrap() => throw new Exception("Tried to unwrap None.");
|
||||
public T Expect(string message) => throw new OptionException(message);
|
||||
public T Unwrap() => throw new OptionException("Tried to unwrap None.");
|
||||
public T UnwrapOr(T def) => def;
|
||||
public T UnwrapOrElse(Func<T> f) => f();
|
||||
public IOption<T> And(IOption<T> other) => this;
|
||||
|
||||
Reference in New Issue
Block a user