Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try catch の勉強 #64

Open
kochigami opened this issue Jul 19, 2017 · 0 comments
Open

try catch の勉強 #64

kochigami opened this issue Jul 19, 2017 · 0 comments

Comments

@kochigami
Copy link
Owner

In [4]: for i in range(3):
   ...:     try:
   ...:         print i
   ...:         a = i / 0.0
   ...:         print a
   ...:     except:
   ...:         print "NG"
   ...:         continue
   ...:    
0
NG
1
NG
2
NG

In [5]: for i in range(3):
   ...:     try:
   ...:         print i
   ...:         a = i / 0.0
   ...:         print a
   ...:     except:
   ...:         print "NG"
   ...:        
0
NG
1
NG
2
NG

In [5]: for i in range(3):
   ...:     try:
   ...:         print i
   ...:         a = i / 0.0
   ...:         print a
   ...:     except:
   ...:         print "NG"
   ...:        
0
NG
1
NG
2
NG

In [6]: for i in range(3):
   ...:     try:
   ...:         print i
   ...:         a = i / 0.0
   ...:         print a
   ...:     except:
   ...:         print "NG"
   ...: print "hello"
   ...:
0
NG
1
NG
2
NG
hello

In [7]: for i in range(3):
   ...:     try:
   ...:         print i
   ...:     except:
   ...:         print "NG"
   ...: print "hello"
   ...:
0
1
2
hello

In [9]: def hoge():
   ...:     for i in range(100):
   ...:         try:
   ...:             print i
   ...:             a = i / 0.0
   ...:             print a
   ...:         except:
   ...:             print "NG"
   ...:             if i == 2:
   ...:                 return "hoge"
   ...:            

In [10]: a = hoge()
0
NG
1
NG
2
NG

In [11]: a
Out[11]: 'hoge'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant