mardi 27 janvier 2015

Putting custom error messages in Python


Vote count:

0




I want to create custom error messages for a function.



def tr( launch_speed , launch_angle_deg , num_samples ):

#Error displays
try:
launch_speed>0
except:
raise Exception("Launch speed has to be positive!")
try:
0<launch_angle_deg<90
except:
raise Exception("Launch angle has to be 0 to 90 degrees!")
try:
um_samples = int(input())
except:
raise Exception("Integer amount of samples!")
try:
num_samples >=2
except:
raise Exception("At least 2 samples!")


Essentially, what I want is to get an error message every time a wrong value has been written in the function variables, and I've tried creating these messages based on what I've gathered on the Internet, but it doesn't seem to work.



asked 1 min ago







Putting custom error messages in Python

Aucun commentaire:

Enregistrer un commentaire