<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ojukwu Chimzuruoke Levi</title>
    <description>The latest articles on DEV Community by Ojukwu Chimzuruoke Levi (@mettle-x).</description>
    <link>https://dev.to/mettle-x</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3746835%2Fcf728734-fb36-46c0-a297-a9a0f511f7f2.jpg</url>
      <title>DEV Community: Ojukwu Chimzuruoke Levi</title>
      <link>https://dev.to/mettle-x</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mettle-x"/>
    <language>en</language>
    <item>
      <title>ERROR HANDLING IN PYTHON</title>
      <dc:creator>Ojukwu Chimzuruoke Levi</dc:creator>
      <pubDate>Mon, 02 Feb 2026 10:31:45 +0000</pubDate>
      <link>https://dev.to/mettle-x/error-handling-in-python-3j1c</link>
      <guid>https://dev.to/mettle-x/error-handling-in-python-3j1c</guid>
      <description>&lt;p&gt;ERROR HANDLING IN PYTHON&lt;br&gt;
What are errors? These "errors" are feedback that tells you what needs to be changed, not failures. Programming functions in precisely the same manner. Fundamentally, an error is Python's way of expressing, "I don't know how to proceed with what you have asked me to do."&lt;br&gt;
    The Two Main Error Families&lt;br&gt;
Syntax Errors: The Grammar Mistakes&lt;br&gt;
Python requires specific structures and once they are not followed it throws out error. These mistakes happen at the parsing stage, prior to your code executing.&lt;br&gt;
Exceptions: The Runtime Surprises&lt;br&gt;
Everything is grammatically fine, yet something unexpected occurs for instance  trying to open a file that doesn't exist or dividing by zero.&lt;br&gt;
      Basic Error Handling&lt;br&gt;
Python uses Try, Except, Else, Finally to anticipate errors and sort them out instead of allowing your code to crash.&lt;br&gt;
Example: try-except&lt;br&gt;
try:&lt;br&gt;
    y = int(input("Enter a number: "))&lt;br&gt;
    print(10 / y)&lt;br&gt;
except ZeroDivisionError:&lt;br&gt;
    print("You cannot divide by zero.")&lt;br&gt;
except ValueError:&lt;br&gt;
    print("Invalid input. Please enter a number.")&lt;br&gt;
 &lt;br&gt;
If the user inputs zero “0” instead of crashing your code, it will print “You cannot divide by zero". This informs the user of their error. Also if the user enters letters instead of number the except ValueError will be executed.&lt;br&gt;
 &lt;br&gt;
Example: Catching multiple exceptions&lt;br&gt;
try:&lt;br&gt;
    result = 10 / int("0")&lt;br&gt;
except Exceptions:&lt;br&gt;
    print("An error occurred.")&lt;br&gt;
This targets the whole error and prints “an error occured", it is not specific.&lt;br&gt;
Example: Else with try-except&lt;br&gt;
try:&lt;br&gt;
    num = int(input("Enter a number: "))&lt;br&gt;
except ValueError:&lt;br&gt;
    print("Invalid number.")&lt;br&gt;
else:&lt;br&gt;
    print("You entered:", num)&lt;br&gt;
 &lt;br&gt;
Example: Finally block&lt;br&gt;
    file = open("media.ppt")&lt;br&gt;
except FileNotFoundError:&lt;br&gt;
    print("File not found.")&lt;br&gt;
finally:&lt;br&gt;
    print("Execution completed.")&lt;br&gt;
Finally runs whether there is error or not. It is used in cleaning up. &lt;br&gt;
 &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
