
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to catch NameError Exception in Python?
NameErrors are raised when your code refers to a name that does not exist in the current scope. For example, an unqualified variable name.
The given code is rewritten as follows to catch the exception and find its type.
Example
import sys try: def foo(): print magnolia foo() except NameError as e: print e print sys.exc_type
Output
C:/Users/TutorialsPoint1/~.py global name 'magnolia' is not defined <type 'exceptions.NameError'>
- Related Questions & Answers
- How to catch KeyError Exception in Python?
- How to catch IOError Exception in Python?
- How to catch ArithmeticError Exception in Python?
- How to catch OverflowError Exception in Python?
- How to catch IndexError Exception in Python?
- How to catch EOFError Exception in Python?
- How to catch SyntaxError Exception in Python?
- How to catch IndentationError Exception in python?
- How to catch TypeError Exception in Python?
- How to catch EnvironmentError Exception in Python?
- How to catch LookupError Exception in Python?
- How to catch ZeroDivisionError Exception in Python?
- How to catch FloatingPointError Exception in Python?
- How to catch StandardError Exception in Python?
- How to catch StopIteration Exception in Python?
Advertisements