Python learning - 17. Error exception handling
Error exception handling
- error type
- SyntaxError (SyntaxError)
- Semantic errors
such as x = 5 / 0, display ZeroDivisionError - logical error
- exception handling
basic format
try: # code that may generate an exception except specified exception as alias: # execute operation except: # all remaining exceptions # execute operation else: # no exception execute operation finally: # close resources that must be manually released
Manually throw an exception
raise a specified error name (error prompt)
(generally used to remind that the method has not been implemented)
Python learning - 17. Error exception handling Related posts
- from entry to proficient in Python Learning Lesson 17: Python Standard Library
IntroductionThe Python standard library is installed with Python and contains many useful modules. So it is very important for a Python developer to be familiar with the Python standard library. Most of your problems can be solved with modules in these libraries.sys moduleThe sys module contains fun ...
- Reinforcement Learning (17) Model-based Reinforcement Learning and Dyna Algorithm Framework
    Earlier we discussed Value Based RL and Policy Based RL. In this article, we discuss the last genre of reinforcement learning, Model Based RL. And Dyna, a model-based reinforcement learning algorithm framework.    This article mainly refers to Lecture 8 of ...
- beginners learn Python? Stanford University leaks 17 practical tips to get started quickly!
Before starting today's topic, let's discuss a question: what language should a beginner programmer learn?Every day every year, many new students ask this seemingly simple question that makes it difficult to give an accurate answer. As a novice, even if you scratch your head, you can't imagine which ...
- Learn CSS Grid by Building 5 Layouts in 17 minutes
CSS Grid is a tool you can use to help create layouts for your website. It's especially useful if you need to think about the position, layers, or sizes of different elements.CSS Grid is complicated and there are many things to learn. But the good news is that you don't need to know everything all a ...
- Self-learning Java——day_17 thread pool, Lambda expression
1. Thread pool1.1 Inter-thread communicationWhen multiple threads execute concurrently, the CPU switches threads randomly by default. When we need multiple threads to complete a task together, and we want them to execute regularly, then some coordination and communication between multiple threads ar ...
- Java Learning (17) Multithreading in Java
Multithreading in JavaWhat is a process?A process is a running program, an independent unit for the system to allocate and call resources. Each process has its own memory space and system resources.What is a threadEach running program is a process, and there can be multiple execution units running s ...
- "Stupid Way" to learn Python Lesson11-17
1. Homework contentStupid way to learn Python exercises 11-17 and bonus points.Second, the job code:#习题11 Ask a question print("How old are you?"), age = input() print("How tall are you?"), height = input() print("How much do you weight?"), weight = input() print("So, you're %r old, %r tall and %r h ...
- Machine Learning-Basic Algorithms (17)
Article DirectoryMachine Learning-Basic Algorithms (17)1. Installation of Hmmlearn2. Invisible Markov Model PracticeThree, trainHMMMachine Learning-Basic Algorithms (17)1. Installation of Hmmlearn2. Invisible Markov Model PracticeThree, trainHMM# !/usr/bin/python# -*- coding:utf-8 -*-import mathimpo ...
- Python learning from scratch Episode 17 - Serialization
SerializationWe call the process of transforming objects (variables) from memory into storable or transferable serialization, which is called pickling in Python, and in other languages.It is also called serialization, marshalling, flattening, etc. in the language, all of which have the same meaning. ...
- Java learning day17-keyword static
1. Keyword static  When we write a class, we are actually describing the properties and behaviors of its object, and no substantial object is produced. Only through the new keyword will the object be produced, and then the system will allocate memory space to the object. The method can be ...
- Learning from a whopping 17 users
by Jacob EvelynFour open source lessons—from a whopping 17 usersHaving more than 17 users would be overwhelming! (At least, that’s what I tell myself to feel better about it.)I have an open-source project. It has 17 users.It actually has somehow scraped together a few hundred stars on GitHub, managi ...
- Python learning - 17. Error exception handling
Error exception handlingerror typeSyntaxError (SyntaxError)Semantic errors such as x = 5 / 0, display ZeroDivisionErrorlogical errorexception handlingbasic formattry: # code that may generate an exception except specified exception as alias: # execute operation except: # all remaining exceptions # e ...
- python-day17 (formal study)
contentBag1. What is a package?Second, why have a package?3. How to use the bag?3.1 Modules and packages3.2 Expansion module function3.3 Modify the __init__.py fileAbsolute and relative importsPrecautionsThe module will not be summarized, just go to https://www.cnblogs.com/nickchen121/p/10718112.htm ...
- [Deep Learning Basics-17] Unsupervised Learning-Hierarchical clustering Hierarchical Clustering-python Implementation
# -*- coding: utf-8 -*-import numpy as npfrom scipy.cluster.hierarchy import dendrogram, linkage, fclusterfrom matplotlib import pyplot as pltdef hierarchy_cluster(data, method='average', threshold=5.0): ''' Hierarchical clustering Arguments: data [[0, float, ...], [float, 0, ...]] -- the distance b ...
- Learn Data Visualization in This Free 17-Hour Course
Business is becoming increasingly data driven and this data needs to be visualized to make it easier to understand. Data Visualization is a growing field with many opportunities.We've released a comprehensive 17-hour course on data visualization that is perfect for anyone new to the field. The cours ...
- "Stupid Way" to learn Python3 Exercise 17
When I was doing exercise 21, I suddenly became a little vague about some of the previous knowledge, so I went to the previous knowledge points. When I saw this question, I suddenly thought of trying to write it like this, and then I found that it could meet the author's requirements.from sys import ...
Recent Posts
- javascript-onbeforeUnload does not return or no dialog box is displayed
I am developing a web application in java EE using richfaces. There is a link to log out the user. When the user leaves the page or closes the browser, I should log out the user because I have to know when he left our page. This is a snippet:function fireEvent (obj, evt) { var fireOnThis = obj; if( document.createEvent ) { var evObj = document.createEvent('MouseEvents'); evObj.initEvent (evt, true, false); fireOnThis.dispatchEvent(evObj); } else if( document.createEventObject ) { fireOnThis.fir...
- C# widget ---- countdown automatic shutdown widget
Picture abovepublic partial class Form1: Form { private DateTime StartTime; private const int hours = 0; private const int minutes = 30; private const int sec = 0; private TimeSpan sCountdown = new TimeSpan(hours, minutes, sec); private bool FromStatus = false; public Form1() { InitializeComponent(); this.Size = new Size(525, 260); this.tableLayoutPanel1.Height = 135; } private void CenterFrom() { this.Hide(); this.Size = new Size(525, 260); this.Location = new Point((Screen.PrimaryScreen.Workin...
- javascript - run tasks in the background in NativeScript
I'm using NativeScript 2.0 and I'm developing an Android module that doesn't allow running in the main thread!Is there a module I can use to run a function in a background thread?Or is it possible to use something like AsyncTask in"native"JavaScript code (not TypeScript!)?Solution:nativescript adds ...
- php - How to approve new articles and edits in Mediawiki?
When users create or edit articles, I first have to approve them, then publish them. How can I achieve this or what extension makes this possible?Solution:Try the FlaggedRevs extension. It adds a status to each article, the status can be changed when the article is edited (based on the editor's perm...
- Python handwriting recognition software?
Is there a Python handwriting recognition library? Handwriting recognition package, what is the input for .jpg images? .pdf image?Solution:Zinnia is a C/C++ library with SWIG generating wrappers for Perl/Python/Ruby. It has a BSD license and converts user strokes provided as coordinates into charact...
- python - Detect and exclude outliers in Pandas dataframes
I have a pandas dataframe with few columns.Now I know that some rows are outliers based on a certain column value.For example column - 'Vol' has all values around 12xx and one value is 4000 (outlier).Now I want to exclude those rows that have a 'Vol' column. So basically I need to put a filter on th...
- Which is the Java source code to fill the system properties
With System.getProperty(String key), you can get the value of certain Java system properties, but my question is how does Java fill these values, and more precisely, where is the source of this information. I'm looking for something like here Place, but didn't find the answer.My problem is that I am trying to test some behavior of the code, and I want to change the system property of the os.name value outside java (I know I can set the value using System.setProperty(String key, String value), bu...
- java-start and stop threads repeatedly in android
Here I have a method called Method1() that will start a thread when the method is called odd time and stop the thread when it is called even time. When I call the method via Button.onClick event , the following snippet works. Is this the correct way to suspend and resume a thread? Is my method threa...
- java-help try to understand the modulus operations in loop arrays
I have a small problem trying to figure out how to calculate modulo arithmetic. I'm building a queue, so I have a circular array. I can't figure out how this modulo arithmetic works.Given q: Character array with a length of 5 elements, the MAX constant gives the maximum length of the array"5". Rarely is an int, which represents the first available point in the array qpublic void enqueue(Character c)throws FullQueueException{ if(size()== MAX -1){ //if only 1 place left, is full, throw exc throw n...
- What is the way to delete words without numbers in the Python list?
a = ['in 1978 by', 'History', 'members', 'albums', 'June 4th, 1979', 'October 7,1986): "The Lounge', 'In 1984 the', 'early 1990s; prominent']The above list has words like history, members without numbers, so I want to delete them# output would be a = ['in 1978 by', 'June 4th, 1979', 'October 7, 1986', 'In 1984 the', 'early 1990s; prominent']Solution:Keep what you want:a = ['in 1978 by', 'History', 'members', 'albums', 'June 4th, 1979', 'October 7,1986): "The Lounge', 'In 1984 the', 'early 1990s;...