+ 2

Can I make my own exceptions in python?

Example: if user has to input his name...and user input name of len(1) then i want that it show NameTooShortError(This is not default error).

22nd May 2018, 12:37 PM
Abhishek Verma
Abhishek Verma - avatar
4 Respostas
+ 4
You may want to use a if statement Here’s what you asked for: http://www.sololearn.com/app/JUMP_LINK__&&__python__&&__JUMP_LINK/playground/cI4mcQVKHsy1/
22nd May 2018, 12:45 PM
Hampus Mathiesen
Hampus Mathiesen - avatar
22nd May 2018, 1:04 PM
Rahul George
Rahul George - avatar
+ 2
you could use if statement and just print error message or if you want it to exit with an exception, if i don't remember incorrectly you can just do raise Exception("error string here") or you could make a custom class/function
22nd May 2018, 2:33 PM
Markus Kaleton
Markus Kaleton - avatar