Python - Error Types

Python - Error Types

Errors in Python can be classified into
  • Compile-time errors
  • Runtime errors
  • Logical errors
Compile-time errors:
  • syntax errors can be classified as compile-time errors
  • For example, let us check the output for the below Python block.
x = 0
if x = 0
    print(x)

After compiling above program, output is as below:

 File "F:\python-progrm\Python-Tutorial-1.py", line 10
    if x = 0
         ^
SyntaxError: invalid syntax

We can observe that the line number is indicated with the error line

Run time errors:
  • errors reported by Python Virtual Machine (PVM) during the byte code execution
  • while syntax errors are compiler-time errors any errors which are syntactically correct and cannot be executed come under run time errors
  • Any statement which PVM cannot be executed shall be reported as run time error
  • Exception handlers are coded by programmers to handle the run time errors
  • for example, let us check the output for the below Python block.
ls = ['0','1']
print(ls[2])

When we run the above block, it reports below error.

File "F:\python-progrm\Python-Tutorial-1.py", line 10, in <module>
    print(ls[2])
IndexError: list index out of range

Logical errors:
  • These unlike run time and compiler errors have no relation to the PVM or Python compiler
  • These completely are a fault of the programmer because of which intended program output is not achieved
  • Example could be while calculating an average of 10 elements, user adding 10 elements but dividing only by 9 gives a wrong output.

    Post a Comment

    19 Comments

    1. Thanks for sharing nice blog. I have taken Embedded Development Services in India and their service is very good.

      ReplyDelete
    2. For resolution to Norton scan error it is advisable to get the software removed from the system further the user should get the software reinstalled. For more information the user should get connected with the team of certified Norton technicians. There is no such issue that cannot be resolved by the Norton antivirus customer support number of the experts.

      ReplyDelete
    3. Thansk For Good Posting Most powerfull Information But And Try It Kaspersky technical team the team can be reached for help through Emails, live chats and also through calls at https://www.pinterest.co.uk/pin/655836764474915279.

      ReplyDelete
    4. Your site is acceptable and your site contact is useful individuals can learn and take data here I am learnig heaps of think like I have an assistance related your site like yippee on the off chance that you confronting some probleme identified with hurray blunder so contact on yahoo support number uk and yahoo helpline number uk

      ReplyDelete
    5. you site is good people can take easliy from your site kaspersky hepline number is best service kaspersky toll free number uk

      ReplyDelete
    6. The blog has been written by a skilled and an experienced writing professional and thus it is helping out a lot of people.CLEAR NETFLIX VIEWING HISTORY ON LAPTOPS

      ReplyDelete
    7. The blog has been written by a skilled and an experienced writing professional and thus it is helping out a lot of people.CLEAR NETFLIX VIEWING HISTORY ON LAPTOPS

      ReplyDelete
    8. Undoubtedly everyone who has the knowledge of website designing and developing would be able to understand the creativity that has been used by the professionals

      here on the website. Reason If Netflix Is Not

      Connecting On TV

      ReplyDelete
    9. The writer is advised to write more and more and also is advised to share all that writing here as that would bring more audience for the content. avast helpline number uk | avast support number uk | avast contact number uk

      ReplyDelete
    10. The process to troubleshoot BullGuard antivirus error code 232 is an easy thing to be done for that, the user should check for program incompatibility also the program should be updated to the latest version. If required then to know more the user should get in touch with the team of technicians as and when needed.bullguard contact number uk bullguard toll free number uk | How to get data backup created through BullGuard

      ReplyDelete
    11. yahoo mail is provding good service for your divice. if you while using yahoo mail sometime you have to problem then you contact via YAHOO PHONE NUMBER 800-368-9067 CUSTOMER SERVICE UK

      ReplyDelete
    12. The content is very informative and good for the reading, for fixing McAfee problems please take support from the trained experts team. Mcafee Helpline Number UK

      ReplyDelete
    13. The content is very informative and good for the reading, for fixing McAfee problems please take support from the trained experts team. Mcafee Helpline Number UK

      ReplyDelete
    14. The content is very informative and good for the reading, for fixing McAfee problems please take support from the trained experts team. Mcafee Helpline Number UK

      ReplyDelete