Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would i make a custom error message in python

In a python program I am making, I want it to only take integers, and if it gets a string say "There has been an error in the system." instead of murmering sensless information the user will not understand

like image 1000
user2196227 Avatar asked Dec 30 '13 17:12

user2196227


1 Answers

Use a try-except block to capture the error and use the raise statement to say the error message of your choice:

try:
    a = int(input())
except:
    raise Exception('There has been an error in the system')
like image 73
K DawG Avatar answered Oct 19 '22 14:10

K DawG