Add exceptions

This commit is contained in:
ShabOl 2023-11-25 23:25:32 +04:00
parent 1a799909f9
commit dd34fcbfa9
3 changed files with 66 additions and 5 deletions

View File

@ -0,0 +1,28 @@
using System.Runtime.Serialization;
namespace AirBomber.Exceptions
{
[Serializable]
internal class EntityNotFoundException : ApplicationException
{
public EntityNotFoundException(int i)
: base($"Не найден объект по позиции {i}")
{ }
public EntityNotFoundException()
: base()
{ }
public EntityNotFoundException(string Message)
: base(Message)
{ }
public EntityNotFoundException(string Message, Exception Exception)
: base(Message, Exception)
{ }
public EntityNotFoundException(SerializationInfo Info, StreamingContext Context)
: base(Info, Context)
{ }
}
}

View File

@ -0,0 +1,28 @@
using System.Runtime.Serialization;
namespace AirBomber.Exceptions
{
[Serializable]
internal class StorageOverflowException : ApplicationException
{
public StorageOverflowException(int Count)
: base($"В наборе превышено допустимое количество {Count}")
{ }
public StorageOverflowException()
: base()
{ }
public StorageOverflowException(string Message)
: base(Message)
{ }
public StorageOverflowException(string Message, Exception Exception)
: base(Message, Exception)
{ }
public StorageOverflowException(SerializationInfo Info, StreamingContext Context)
: base(Info, Context)
{ }
}
}

View File

@ -1,4 +1,6 @@
namespace AirBomber.Generics
using AirBomber.Exceptions;
namespace AirBomber.Generics
{
internal class SetGeneric<T>
where T : class
@ -27,13 +29,13 @@
return i;
}
return -1;
throw new StorageOverflowException();
}
public int Insert(T Entity, int Position)
{
if (Position >= _maxCount)
return -1;
throw new StorageOverflowException();
if (_objects[Position] is null)
{
@ -41,13 +43,16 @@
return Position;
}
return -1;
throw new StorageOverflowException();
}
public bool Remove(int Position)
{
if (Position >= _maxCount)
return false;
throw new EntityNotFoundException();
if (_objects[Position] is null)
throw new EntityNotFoundException();
_objects[Position] = default(T);
return true;