

You can do so by passing in the string to be printed along with the constructor as follows. Say your program is going to be run by a not-so-tech-savvy user, in that case, you might want to print something friendlier. This can be retrieved using the built-in function print(). This will print the default error message as follows list index out of rangeĮach Exception type comes with its own error message.

#Python slack client catch error how to
The example below shows how to print such an Error message. In other words, if your program is to be run on the command line and you wish to log why the program just crashed then it is better to use an “Error message” rather than an “Exception Type”.

The Exception type is definitely useful for debugging, but, a message like Inde圎rror might sound cryptic and a good understandable error-message will make our job of debugging easier without having to look at the documentation. Piece#2: Printing Exception Value a.k.a Error message In order to do that, the best place to start is the official documentation.įor built in exceptions you can have a look at the Python Documentationįor Exception types that come with the libraries that you use with your code, refer to the documentation of your library.
#Python slack client catch error code
Now that we have the “Exception Type”, next we will probably need to get some information about that particular type so that we can get a better understanding of why our code has failed. print(type(e)) Where to get more details about Exception Types Then by using the built-in python function type(), we have printed out the class name that the object e belongs to. What we have done is, we have assigned the caught exception to an object named “ e”. On running the code, we will get the following output Īs you can see we just extracted and printed out the information about the class to which the exception that we have just caught belongs to! The except clause catches the Inde圎rror exception and prints out Exception type. Then we have tried to print the 3rd/non-existent item in the list. Here, in the try clause, we have declared a List named my_list and initialized the list with 2 items. Let us improve our Example 1 above by putting the problematic code into try and except clauses. The Exception Type refers to the class to which the Exception that you have just caught belongs to.

You can get the following 3 pieces of data from exceptions What kind of information can you get from Exceptions? Let us start by learning what the 3 pieces of information are. In this Python Tutorial let us learn about the 3 different pieces of information that you can extract and use from the Exceptions caught on your except clauses, and see the best ways to use each of these pieces in our Python programs.
