way as those python raises the following may not be the most useful python code ever pennedbut it makes the point--raising the built-in indexerror exceptiontryraise indexerror except indexerrorprint('got exception'got exception trigger exception manually as usualif they're not caughtuser-triggered exceptions are propagated up to the toplevel default exception handler and terminate the program with standard error messageraise indexerror traceback (most recent call last)file ""line in indexerror as we'll see in the next the assert statement can be used to trigger exceptionstoo--it' conditional raiseused mostly for debugging purposes during developmentassert false'nobody expects the spanish inquisition!traceback (most recent call last)file ""line in assertionerrornobody expects the spanish inquisitionuser-defined exceptions the raise statement introduced in the prior section raises built-in exception defined in python' built-in scope as you'll learn later in this part of the bookyou can also define new exceptions of your own that are specific to your programs user-defined exceptions are coded with classeswhich inherit from built-in exception classusually the class named exceptionclass alreadygotone(exception)pass user-defined exception def grail()raise alreadygotone(raise an instance trygrail(except alreadygotoneprint('got exception'got exception catch class name as we'll see in the next an as clause on an except can gain access to the exception object itself class-based exceptions allow scripts to build exception categorieswhich can inherit behaviorand have attached state information and methods they can also customize their error message text displayed if they're not caught exception basics