-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexcept1.py
More file actions
100 lines (88 loc) · 2.29 KB
/
except1.py
File metadata and controls
100 lines (88 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2020 wmsj100 <wmsj100@hotmail.com>
#
# Distributed under terms of the MIT license.
"""
"""
def excep():
try:
x = input('first number')
y = input('second number')
print(int(x)/int(y))
except ZeroDivisionError:
print('The second number can\'t be zero.')
class Calculate:
flag = False
def cals(self, excp):
try:
return eval(excp)
except ZeroDivisionError:
if self.flag:
return 'The Second number can\'t be zero'
else:
raise
except TypeError:
if self.flag:
return 'Please just input number'
else:
raise
except NameError:
if self.flag:
return 'Please make sure param has defined'
else:
raise
class Cal1:
flag = False
def cals(self,exprval):
try:
return eval(exprval)
except (ZeroDivisionError,NameError,TypeError):
return 'Please input correct number'
class Cal2:
flag = False
def cals(self,exprval):
try:
return eval(exprval)
except (ZeroDivisionError,NameError,TypeError) as e:
print(e)
class Cal3:
flag = False
def cals(self,exprval):
try:
return eval(exprval)
except (ZeroDivisionError,NameError,TypeError) as e:
print(e)
except Exception as e:
print("other error: %s" % e)
class Cal4:
def cals(self,exprval):
while True:
try:
print(eval(exprval))
except Exception as e:
print("other error: %s" % e)
else:
break
class Cal5:
def cals(self,exprval):
try:
return eval(exprval)
except Exception as e:
print("other error: %s" % e)
else:
print("start planing ,not error")
finally:
print("finally!!!")
class Cal6:
def fault(self):
raise Exception('Something is error')
def ignore(self):
self.fault()
def deal(self):
try:
self.fault()
except:
print("thsi is some error,please deal")