From db8ea262af4a123963ea606f98b211ecb2aaaf9f Mon Sep 17 00:00:00 2001 From: xom9k Date: Sun, 23 Feb 2025 12:07:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Exceptions/ElementExistsException.cs | 20 +++++++++++++++++++ .../Exceptions/ElementNotFoundException .cs | 17 ++++++++++++++++ .../Exceptions/IncorrectDatesException .cs | 13 ++++++++++++ .../Exceptions/NullListException.cs | 12 +++++++++++ .../Exceptions/StorageException .cs | 12 +++++++++++ 5 files changed, 74 insertions(+) create mode 100644 MagicCarpetProject/MagicCarpetContracts/Exceptions/ElementExistsException.cs create mode 100644 MagicCarpetProject/MagicCarpetContracts/Exceptions/ElementNotFoundException .cs create mode 100644 MagicCarpetProject/MagicCarpetContracts/Exceptions/IncorrectDatesException .cs create mode 100644 MagicCarpetProject/MagicCarpetContracts/Exceptions/NullListException.cs create mode 100644 MagicCarpetProject/MagicCarpetContracts/Exceptions/StorageException .cs diff --git a/MagicCarpetProject/MagicCarpetContracts/Exceptions/ElementExistsException.cs b/MagicCarpetProject/MagicCarpetContracts/Exceptions/ElementExistsException.cs new file mode 100644 index 0000000..8d4f5a2 --- /dev/null +++ b/MagicCarpetProject/MagicCarpetContracts/Exceptions/ElementExistsException.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicCarpetContracts.Exceptions; + +public class ElementExistsException : Exception +{ + public string ParamName { get; private set; } + + public string ParamValue { get; private set; } + + public ElementExistsException(string paramName, string paramValue) : base($"There is already an element with value{paramValue} of parameter {paramName}") + { + ParamName = paramName; + ParamValue = paramValue; + } +} diff --git a/MagicCarpetProject/MagicCarpetContracts/Exceptions/ElementNotFoundException .cs b/MagicCarpetProject/MagicCarpetContracts/Exceptions/ElementNotFoundException .cs new file mode 100644 index 0000000..ed82472 --- /dev/null +++ b/MagicCarpetProject/MagicCarpetContracts/Exceptions/ElementNotFoundException .cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicCarpetContracts.Exceptions; + +public class ElementNotFoundException : Exception +{ + public string Value { get; private set; } + + public ElementNotFoundException(string value) : base($"Element not found at value = {value}") + { + Value = value; + } +} diff --git a/MagicCarpetProject/MagicCarpetContracts/Exceptions/IncorrectDatesException .cs b/MagicCarpetProject/MagicCarpetContracts/Exceptions/IncorrectDatesException .cs new file mode 100644 index 0000000..c9b3600 --- /dev/null +++ b/MagicCarpetProject/MagicCarpetContracts/Exceptions/IncorrectDatesException .cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicCarpetContracts.Exceptions; + +public class IncorrectDatesException : Exception +{ + public IncorrectDatesException(DateTime start, DateTime end) : base($"The end date must be later than the start date.. StartDate: " + + $"{start:dd.MM.YYYY}. EndDate: {end:dd.MM.YYYY}") { } +} diff --git a/MagicCarpetProject/MagicCarpetContracts/Exceptions/NullListException.cs b/MagicCarpetProject/MagicCarpetContracts/Exceptions/NullListException.cs new file mode 100644 index 0000000..64ca6ae --- /dev/null +++ b/MagicCarpetProject/MagicCarpetContracts/Exceptions/NullListException.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicCarpetContracts.Exceptions; + +public class NullListException : Exception +{ + public NullListException() : base("The returned list is null") { } +} diff --git a/MagicCarpetProject/MagicCarpetContracts/Exceptions/StorageException .cs b/MagicCarpetProject/MagicCarpetContracts/Exceptions/StorageException .cs new file mode 100644 index 0000000..d879520 --- /dev/null +++ b/MagicCarpetProject/MagicCarpetContracts/Exceptions/StorageException .cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagicCarpetContracts.Exceptions; + +public class StorageException : Exception +{ + public StorageException(Exception ex) : base($"Error while working in storage: {ex.Message}", ex) { } +}