There might arise a situation where there is a need for additional information from an exception raised by Python.
Python has two types of exceptions namely, Built-In Exceptions and User-Defined Exceptions.
Why use Argument in Exceptions?
Using arguments for Exceptions in Python is useful for the following reasons:
- It can be used to gain additional information about the error encountered.
- As contents of an Argument can vary depending upon different types of Exceptions in Python, Variables can be supplied to the Exceptions to capture the essence of the encountered errors. Same error can occur of different causes, Arguments helps us identify the specific cause for an error using the except clause.
- It can also be used to trap multiple exceptions, by using a variable to follow the tuple of Exceptions.
Arguments in Buil-in Exceptions:
The below codes demonstrates use of Argument with Built-in Exceptions:
This is the Argument division by zero
This is the Argument unsupported operand type(s) for /: 'str' and 'int'
Arguments in User-defined Exceptions:
The below codes demonstrates use of Argument with User-defined Exceptions:
This is the Argument 'Some Error Data'
Exception occurred: (2, 6, 'Not Allowed')
- Pass list as command line argument in Python
- Python | Raising an Exception to Another Exception
- Passing function as an argument in Python
- Python Lambda with underscore as an argument
- Command-Line Option and Argument Parsing using argparse in Python
- Pass by reference vs value in Python
- Python pass Statement
- break, continue and pass in Python
- Difference between continue and pass statements in Python
- Python - pass multiple arguments to map function
- Python | Split and Pass list as separate parameter
- How to write an empty function in Python - pass statement?
- Python Exception Handling
- Loops and Control Statements (continue, break and pass) in Python
- Multiple Exception Handling in Python
- Python | Reraise the Last Exception and Issue Warning
- Create an Exception Logging Decorator in Python
- How to pass multiple arguments to function ?
- Python - Read blob object in python using wand library
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.