![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 27104 Articles for Server Side Programming
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
2K+ Views
In python documentation, SystemExit is not a subclass of Exception class. BaseException class is the base class of SystemExit. So in given code, we replace the Exception with BaseException to make the code workExampletry: raise SystemExit except BaseException: print "It works!"OutputIt works!The exception inherits from BaseException instead of StandardError or Exception so that it is not accidentally caught by code that catches Exception.We would rather write the code this wayExampletry: raise SystemExit except SystemExit: print "It works!"OutputIt works!
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
1K+ Views
When an iterator is done, it’s next method raises StopIteration. This exception is not considered an error.We re-write the given code as follows to catch the exception and know its type.Exampleimport sys try: z = [5, 9, 7] i = iter(z) print i print i.next() print i.next() print i.next() print i.next() except Exception as e: print e print sys.exc_type Output 5 9 7
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
389 Views
There is the Exception class, which is the base class for StopIteration, StandardError and Warning. All the standard errors are derived from StandardError. Some standard errors like ArithmeticErrror, AttributeError, AssertionError are derived from base class StandardError.When an attribute reference or assignment fails, AttributeError is raised. For example, when trying to reference an attribute that does not exist:We rewrite the given code and catch the exception and know it type.Exampleimport sys try: class Foobar: def __init__(self): self.p = 0 f = Foobar() print(f.p) print(f.q) except Exception as e: print e print sys.exc_type print 'This is an example of StandardError exception'Output0 Foobar ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
1K+ Views
FloatingPointError is raised by floating point operations that result in errors, when floating point exception control (fpectl) is turned on. Enabling fpectl requires an interpreter compiled with the --with-fpectl flag.The given code is rewritten as follows to handle the exception and find its type.Exampleimport sys import math import fpectl try: print 'Control off:', math.exp(700) fpectl.turnon_sigfpe() print 'Control on:', math.exp(1000) except Exception as e: print e print sys.exc_type OutputControl off: 1.01423205474e+304 Control on: in math_1
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
434 Views
When zero shows up in the denominator of a division operation, a ZeroDivisionError is raised.We re-write the given code as follows to handle the exception and find its type.Exampleimport sys try: x = 11/0 print x except Exception as e: print sys.exc_type print eOutput integer division or modulo by zero
![Manogna](https://www.tutorialspoint.com/assets/profiles/11051/profile/60_103575-1512718394.jpg)
274 Views
A ValueError is used when a function receives a value that has the right type but an invalid value.The given code can be rewritten as follows to handle the exception and find its type.Exampleimport sys try: n = int('magnolia') except Exception as e: print e print sys.exc_typeOutputinvalid literal for int() with base 10: 'magnolia'
![Manogna](https://www.tutorialspoint.com/assets/profiles/11051/profile/60_103575-1512718394.jpg)
1K+ Views
LookupError Exception is the Base class for errors raised when something can’t be found. The base class for the exceptions that are raised when a key or index used on a mapping or sequence is invalid: IndexError, KeyError.An IndexError is raised when a sequence reference is out of range.The given code is rewritten as follows to catch the exception and find its typeExampleimport sys try: foo = [a, s, d, f, g] print foo[5] except IndexError as e: print e print sys.exc_typeOutputC:/Users/TutorialsPoint1~.py list index out of range
![Manogna](https://www.tutorialspoint.com/assets/profiles/11051/profile/60_103575-1512718394.jpg)
326 Views
EnvironmentError is the base class for errors that come from outside of Python (the operating system, filesystem, etc.). EnvironmentError Exception is a subclass of the StandarError class. It is the base class for IOError and OSError exceptions. It is not actually raised unlike its subclass errors like IOError and OSError.Any example of an IOError or OSError should be an example of Environment Error as well.Exampleimport sys try: f = open ( "JohnDoe.txt", 'r' ) except Exception as e: print e print sys.exc_typeOutput[Errno 2] No such file or directory: 'JohnDoe.txt'
![Manogna](https://www.tutorialspoint.com/assets/profiles/11051/profile/60_103575-1512718394.jpg)
551 Views
TypeErrors are caused by combining the wrong type of objects, or calling a function with the wrong type of object.Exampleimport sys try : ny = 'Statue of Liberty' my_list = [3, 4, 5, 8, 9] print my_list + ny except TypeError as e: print e print sys.exc_typeOutputcan only concatenate list (not ""str") to list
![Manogna](https://www.tutorialspoint.com/assets/profiles/11051/profile/60_103575-1512718394.jpg)
1K+ Views
A IndentationError occurs any time the parser finds source code that does not follow indentation rules. We can catch it when importing a module, since the module will be compiled on first import. You can't catch it in the same module that contains the try/except block, because with this exception, Python won't be able to finish compiling the module, and no code in the module will be run.We rewrite the given code as follows to handle the exceptionExampletry: def f(): z=['foo', 'bar'] for i in z: if i == 'foo': except IndentationError as e: print eOutput"C:/Users/TutorialsPoint1/~.py", line 5 if i ... Read More