Python – Error Types

python Exceptions | اخطاء بايثون المتوقعة

في البداية عند عمل برنامج في لغة بايثون في كثير من الأحيان ينتج عن البرنامج خطأ بعد تشغيله حتى لو لم يكن به أي خطأ في بناء الجملة (syntax). مثل:
ان تطلب من المستخدم قيمة رقمية و بدلاً من ذلك يقوم المستخدم بادخال قيمة نصية وهو ما ينتج عنه خطأ في البرنامج يسمى ValueError.

لذلك هناك العديد و العديد من الاخطاء في بايثون لعل اشهر تلك في برنامج Python هو الخطأ في بناء الجملة (syntax) .
ايسمى هذا الخطأ خطأ نحوي. يقوم مترجم Python بالإبلاغ عن ذلك على الفور .

جدول به الـ exceptions الهامة في Python

يمكنك ان تجد هنا الاخطاء الهامة التي يظهرها برنامج بايثون ستجد الخطأ في قسم ال Exception و ستجد وصف الخطأ في قسم ال Description

Description Exception
Raised when the assert statement failsAssertionError
Raised on the attribute assignment or reference failsAttributeError
Raised when the input() function hits the end-of-file conditionEOFError
Raised when a generator’s close() method is calledGeneratorExit
Raised when the imported module is not foundImportError
Raised when the index of a sequence is out of rangeIndexError
Raised when a key is not found in a dictionaryKeyError
Raised when the user hits the interrupt key (Ctrl+c or delete)KeyboardInterrupt
Raised when an operation runs out of memoryMemoryError
Raised when a variable is not found in the local or global scopeNameError
Raised by abstract methodsNotImplementedError
Raised when a system operation causes a system-related errorOSError
Raised when the result of an arithmetic operation is too large to be representedOverflowError
Raised when a weak reference proxy is used to access a garbage collected referentReferenceError
Raised when an error does not fall under any other categoryRuntimeError
Raised by the next() function to indicate that there is no further item to be returned by the iteratorStopIteration
Raised by the parser when a syntax error is encounteredSyntaxError
Raised when there is an incorrect indentationIndentationError
Raised when the indentation consists of inconsistent tabs and spacesTabError
Raised when the interpreter detects internal errorSystemError
Raised by the sys.exit() functionSystemExit
Raised when a function or operation is applied to an object of an incorrect typeTypeError
Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variableUnboundLocalError
Raised when a Unicode-related encoding or decoding error occursUnicodeError
Raised when a Unicode-related error occurs during encodingUnicodeEncodeError
Raised when a Unicode-related error occurs during decodingUnicodeDecodeError
Raised when a Unicode-related error occurs during translationUnicodeTranslateError
Raised when a function gets an argument of correct type but improper valueValueError
Raised when the second operand of a division or module operation is zeroZeroDivisionError
يعرض الجدول التالي الـ exceptions الهامة في Python

استثناء الخطأ في بايثون

في النهاية يمكنك استثناء الخطأ من خلال فهمك لمفهوم ال Exceptions

try:
    number = int(input("number: "))

except ValueError:
    print("value error")
    exit()
            

4 تعليقات

  1. من اجمل القنوات قناتك بجد شرحك خيااالي تفوق ع ناس كتيرين الهم سنين بالمجال
    الشيي المميز توصل المعلومة لضعيف قبل القوي

اترك ردّاً