F&A Diskussionen
Exceptions and raises
0 Stimmen
1 AntwortIf except can handle common errors very well, doesn't that make the use of raise redundant inside of a try-except block?
For example:
try:
print( 5 / 0 )
except ZeroDivisionError:
raise ValueError("An error occurred!")
What's the difference if we handle it this way:
try:
print( 5 / 0 )
except (ZeroDivisionError, ValueError):
print("An error occurred!")
3 Stimmen
2 Antwortendef manipulate_data(n):
positives,negatives=[],[]
if not isinstance(n,list):
raise ValueError
return
else:
for i in n:
if i>=0:
positives.append(i)
if i<0
negatives.append(i)
new=[len(positives,sum(negatives)]
return new.
Someone kindly assist I keep running it in unitests and I keep getting errors.
Here's the question:
0 Stimmen
2 AntwortenHeute heiß
What is a web browser intension?
1 Votes
Percobaan
0 Votes
Mentors
0 Votes
Thread local : global vs local
0 Votes
Codding lern
0 Votes
Postgrrsql and python
0 Votes
python
0 Votes