From 7ba455c736792ccd899e7424a383a2c4df992831 Mon Sep 17 00:00:00 2001 From: mrcool7387 <146818600+mrcool7387@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:18:07 +0100 Subject: [PATCH 1/2] Create custom-exception-type.md --- .../error-handling/custom-exception-type.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 snippets/python/error-handling/custom-exception-type.md diff --git a/snippets/python/error-handling/custom-exception-type.md b/snippets/python/error-handling/custom-exception-type.md new file mode 100644 index 00000000..bd12fcbc --- /dev/null +++ b/snippets/python/error-handling/custom-exception-type.md @@ -0,0 +1,18 @@ +--- +title: Create Custom Exception Type +description: Create a Custom Exception Type that can be called with raise. +author: mrcool7387 +tags: python,error-creation,organisation,utility +--- + +```py +class ExceptionName(Exception): + def __init__(message: str): + super().__init__(message) + +# Usage +a: int = 1 + +if a > 0: #Simple if function + raise ExceptionName('Error Message') #Rasing the Custom Exception +``` From 07dbbdfb2ac35a95cd664712f8084c9ec36e9145 Mon Sep 17 00:00:00 2001 From: mrcool7387 <146818600+mrcool7387@users.noreply.github.com> Date: Thu, 2 Jan 2025 17:20:03 +0100 Subject: [PATCH 2/2] Changeing some Sinppet Code after Review in custom-exception-type.md Snippet --- snippets/python/error-handling/custom-exception-type.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/python/error-handling/custom-exception-type.md b/snippets/python/error-handling/custom-exception-type.md index bd12fcbc..c985e069 100644 --- a/snippets/python/error-handling/custom-exception-type.md +++ b/snippets/python/error-handling/custom-exception-type.md @@ -6,13 +6,13 @@ tags: python,error-creation,organisation,utility --- ```py -class ExceptionName(Exception): +class ExceptionName(BaseException): def __init__(message: str): super().__init__(message) # Usage a: int = 1 -if a > 0: #Simple if function - raise ExceptionName('Error Message') #Rasing the Custom Exception +if a > 0: + raise ExceptionName('Error Message') ```