DragonECS/src/Utils/Exceptions.cs

105 lines
4.7 KiB
C#
Raw Normal View History

2023-05-30 04:32:09 +08:00
using System;
2023-06-26 01:57:50 +08:00
using System.Runtime.CompilerServices;
2023-05-30 04:32:09 +08:00
using System.Runtime.Serialization;
namespace DCFApixels.DragonECS
{
2023-06-26 02:53:55 +08:00
namespace Internal
2023-06-26 01:57:50 +08:00
{
2023-06-26 02:53:55 +08:00
internal static class Throw
2023-06-26 01:57:50 +08:00
{
2023-06-26 02:53:55 +08:00
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void ArgumentNull()
{
throw new ArgumentNullException();
}
2023-06-26 01:57:50 +08:00
2023-06-26 02:53:55 +08:00
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void ConstraintIsAlreadyContainedInMask(Type type)
{
throw new EcsFrameworkException($"The {EcsDebugUtility.GetGenericTypeName(type)} constraint is already contained in the mask.");
}
2023-06-26 01:57:50 +08:00
2023-06-26 02:53:55 +08:00
//[MethodImpl(MethodImplOptions.NoInlining)]
//public static void ArgumentDifferentWorldsException()
//{
// throw new ArgumentException("The groups belong to different worlds.");
//}
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void ArgumentOutOfRange()
{
throw new ArgumentOutOfRangeException($"index is less than 0 or is equal to or greater than Count.");
}
2023-06-26 01:57:50 +08:00
2023-06-26 02:53:55 +08:00
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Group_AlreadyContains(int entityID)
{
throw new EcsFrameworkException($"This group already contains entity {entityID}.");
}
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Group_DoesNotContain(int entityID)
{
throw new EcsFrameworkException($"This group does not contain entity {entityID}.");
}
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Group_ArgumentDifferentWorldsException()
{
throw new ArgumentException("The groups belong to different worlds.");
}
2023-06-26 01:57:50 +08:00
2023-06-26 02:53:55 +08:00
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Pipeline_MethodCalledAfterInitialisation(string methodName)
{
throw new MethodAccessException($"It is forbidden to call {methodName}, after initialization {nameof(EcsPipeline)}.");
}
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Pipeline_MethodCalledBeforeInitialisation(string methodName)
{
throw new MethodAccessException($"It is forbidden to call {methodName}, before initialization {nameof(EcsPipeline)}.");
}
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Pipeline_MethodCalledAfterDestruction(string methodName)
{
throw new MethodAccessException($"It is forbidden to call {methodName}, after destroying {nameof(EcsPipeline)}.");
}
2023-06-26 01:57:50 +08:00
2023-06-26 02:53:55 +08:00
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void World_InvalidIncrementComponentsBalance()
{
throw new MethodAccessException("Invalid increment components balance.");
}
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void World_GroupDoesNotBelongWorld()
{
throw new MethodAccessException("The Group does not belong in this world.");
}
2023-06-26 01:57:50 +08:00
2023-06-26 02:53:55 +08:00
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Ent_ThrowIsNotAlive(entlong entity)
{
if (entity.IsNull)
throw new EcsFrameworkException($"The {entity} is null.");
else
throw new EcsFrameworkException($"The {entity} is not alive.");
}
2023-06-26 01:57:50 +08:00
}
}
2023-05-30 04:32:09 +08:00
[Serializable]
public class EcsFrameworkException : Exception
{
public EcsFrameworkException() { }
public EcsFrameworkException(string message) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message) { }
public EcsFrameworkException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { }
protected EcsFrameworkException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
[Serializable]
public class EcsRunnerImplementationException : EcsFrameworkException
{
public EcsRunnerImplementationException() { }
public EcsRunnerImplementationException(string message) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message) { }
public EcsRunnerImplementationException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { }
protected EcsRunnerImplementationException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
}