here is class diagram that fully illustrates the exception hierarchysystemexit baseexception keyboardinterrupt exception most other exception when we use the exceptclause without specifying any type of exceptionit will catch all subclasses of baseexceptionwhich is to sayit will catch all exceptionsincluding the two special ones since we almost always want these to get special treatmentit is unwise to use the exceptstatement without arguments if you want to catch all exceptions other than systemexit and keyboardinterruptexplicitly catch exception furthermoreif you do want to catch all exceptionsi suggest using the syntax except baseexceptioninstead of raw exceptthis helps explicitly tell future readers of your code that you are intentionally handling the special case exceptions defining our own exceptions oftenwhen we want to raise an exceptionwe find that none of the built-in exceptions are suitable luckilyit' trivial to define new exceptions of our own the name of the class is usually designed to communicate what went wrongand we can provide arbitrary arguments in the initializer to include additional information all we have to do is inherit from the exception class we don' even have to add any content to the classwe canof courseextend baseexception directlybut then it will not be caught by generic except exception clauses here' simple exception we might use in banking applicationclass invalidwithdrawal(exception)pass raise invalidwithdrawal("you don' have $ in your account"the last line illustrates how to raise the newly defined exception we are able to pass an arbitrary number of arguments into the exception often string message is usedbut any object that might be useful in later exception handler can be stored the exception __init__ method is designed to accept any arguments and store them as tuple in an attribute named args this makes exceptions easier to define without needing to override __init__