- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 pass argument to an Exception in Python?
An exception can have an argument, which is a value that gives additional information about the problem. The contents of the argument vary from exception to exception. You capture an exception's argument by supplying a variable in the except clause as follows
try: b=float(56+78/0) except Exception, Argument: print 'This is the Argument\n', Argument
The output obtained is as follows
This is the Argument integer division or modulo by zero
If you write the code to handle a single exception, you can have a variable follow the name of the exception in the except statement. If you are trapping multiple exceptions, you can have a variable follow the tuple of the exception.
This variable receives the value of the exception mostly containing the cause of the exception. The variable can receive a single value or multiple values in the form of a tuple. This tuple usually contains the error string, the error number, and an error location.
- Argument of an Exception in Python
- How to pass a variable to an exception in Python?
- How to pass an argument to the event handler in Tkinter?
- How to pass Python function as a function argument?
- How to pass an entire structure as an argument to function in C?
- How to pass a dictionary as argument in Python function?
- How to pass entire structure as an argument to function in C language?
- How to pass the address of structure as an argument to function in C?
- How to pass entire array as an argument to a function in C language?
- How to pass individual elements in an array as argument to function in C language?
- Can we pass objects as an argument in Java?
- How to handle an exception in Python?
- How to raise an exception in Python?
- How to pass the address of structure as an argument to function in C language?
- What is the correct way to pass an object with a custom exception in Python?