How to make python exception handing for my app? -


i have finished simple application calculate bmi, however, need create couple of exception handlings in file, such exceptions.py

these exceptions are: empty value exception, integer value exception, , email format exception.

can show me how make these exception handlings in file?

from tkinter import * tkinter import ttk tkinter import messagebox exceptions import exceptions import math , decimal  class bmi_caclulator:      def __init__(self,master):         master.title = ('bmi calculator')         [distracting ui construction code omitted]      def calculate(self):         print('name: {}'.format(self.entry_name.get()))         print('email: {}'.format(self.entry_email.get()))         print('age: {}'.format(self.age.get()))         print('gender: {}'.format(self.gender.get()))         print('weight: {}'.format(self.entry_weight.get()))         print('height: {}'.format(self.entry_ft.get())+ ' feets ' + format(self.entry_in.get())+ ' inchs' )         print('bmi:' + str(self.calculate_bmi()))         print('comments: {}'.format(self.text_comments.get(1.0, 'end')))          self.clear()         messagebox.showinfo(title = 'bmi calculator', message = 'your information submitted!')      def clear(self):         self.entry_name.delete(0, 'end')         self.entry_email.delete(0, 'end')         self.text_comments.delete(1.0, 'end')       def calculate_bmi(self):         self.inchs = int(self.entry_ft.get())* 12 + int(self.entry_in.get())         self.bmi = int(self.entry_weight.get())* 703 /math.pow(self.inchs,2)         return  self.bmi 

the point pythonista made don't need create new exceptions because they'll created in cases.

for example if try creating int empty entry, int('') raise valueerror itself. question should handle exception. function calculateis exceptions happen that's catch them, create meaningful dialog box explaining error , return main tk loop. example:

try    print('bmi:' + str(self.calculate_bmi())) except valueerror:    # make dialog box explaining either height or    # weight invalid numbers ask them try again    return 

it extremely difficult determine whether string valid e-mail address. since aren't using it, if tell them it's invalid may wrong.