Python for Beginners : An Essential Step-by-Step Guide to Quickly Learn Python Programming. A Crash Course for Data Analysis. by Walsh Conley
Author:Walsh, Conley [Walsh, Conley]
Language: eng
Format: epub
Published: 2019-11-11T16:00:00+00:00
Chapter 10:
Exception Handling in the Python Language
The next topic that we need to spend some time exploring in this guidebook is the idea of exception handling. There are going to be times when your code tries to show up some errors or other problem inside the code that you are doing, and this is where the exception is going to occur. Knowing when to recognize these exceptions, how to handle them, and even how to make some of your own can make a big difference in how well you are able to do some of your own coding in Python.
These exceptions are going to be brought up by the compiler in a lot of different situations, and sometimes, they are going to look like a simple error message like you may have seen on your own computer before. It is important to really read through any of these exceptions that come up in your code and read through them so that you can learn what they are about, and how you can handle them properly at the same time. This isn’t meant to be something to scare you, but there are things that you can do to handle these exceptions and to make sure that you are going to be able to handle them in the proper manner.
Now, there are going to be a few exceptions that are already recognized inside the library that you are using in Python. If you want to write out a code with them in there, or if you find that the user is trying to do something that isn’t proper for your program, then the compiler is going to send out an exception about this in order to get it to stop. In some cases, the program you are writing is going to need some extra limitations in place to handle it, and you can raise up, after creating, your own exception.
A good example of an exception that your compiler is automatically going to raise up is when you or the user is to divide it by zero. The compiler is then going to recognize that this is something the user is not able to do, and it is going to send out that exception as an alert. It can also be something that is going to be called up if you, as the programmer, are trying to call up a function and the name is not spelled in the proper manner so there is no match present to bring up.
There are a few different exceptions that are automatically found in your Python library. It is a good idea to take some time to look through them and recognize these exceptions so you can recognize them later on. Some of the most common exceptions that you need to worry about include:
Finally—this is the action that you will want to use to perform cleanup actions, whether the exceptions occur or not.
Assert—this condition is going to trigger the exception inside of the code
Raise—the raise command is going to trigger an exception manually inside of the code.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9899)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9781)
The Mikado Method by Ola Ellnestam Daniel Brolund(9766)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8274)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7768)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7754)
Grails in Action by Glen Smith Peter Ledbrook(7682)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7547)
Windows APT Warfare by Sheng-Hao Ma(6707)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6433)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6397)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6309)
Kotlin in Action by Dmitry Jemerov(5042)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4311)
Functional Programming in JavaScript by Mantyla Dan(4035)
Solidity Programming Essentials by Ritesh Modi(3938)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3724)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3664)
The Ultimate iOS Interview Playbook by Avi Tsadok(3635)
