I am learning Python and when I learned that we can build Custom classes for exception, I got into a confusion of Why ?
for example1 :
class MyException(Exception): def __init__(self, error): self.error = error def __str__(self): # DO THE WORK TO BE DONE FOR THE EXCEPTION print "Here is my custom made exception" + self.error
example 2 :
try: # SOMETHING except: # DO THE WORK TO BE DONE FOR THE EXCEPTION raise Exception("Here is my custom made exception - Whats the reason ?")
If example 2 does the same work as example1, Why do we need custom exception. Is there a scenario why I needed a custom exception when I could just do everything I needed inside except block.