Add exceptions
This commit is contained in:
parent
1a799909f9
commit
dd34fcbfa9
28
AirBomber/Exceptions/EntityNotFoundException.cs
Normal file
28
AirBomber/Exceptions/EntityNotFoundException.cs
Normal 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)
|
||||
{ }
|
||||
}
|
||||
}
|
28
AirBomber/Exceptions/StorageOverflowException.cs
Normal file
28
AirBomber/Exceptions/StorageOverflowException.cs
Normal 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)
|
||||
{ }
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user