control structures and functions custom exceptions |custom exceptions are custom data types (classescreating classes is covered in but since it is easy to create simple custom exception typeswe will show the syntax hereclass exceptionname(baseexception)pass the base class should be exception or class that inherits from exception one use of custom exceptions is to break out of deeply nested loops for exampleif we have table object that holds records (rows)which hold fields (columns)which have multiple values (items)we could search for particular value with code like thisfound false for rowrecord in enumerate(table)for columnfield in enumerate(record)for indexitem in enumerate(field)if item =targetfound true break if foundbreak if foundbreak if foundprint("found at ({ }{ }{ })format(rowcolumnindex)elseprint("not found"the lines of code are complicated by the fact that we must break out of each loop separately an alternative solution is to use custom exceptionclass foundexception(exception)pass tryfor rowrecord in enumerate(table)for columnfield in enumerate(record)for indexitem in enumerate(field)if item =targetraise foundexception(except foundexceptionprint("found at ({ }{ }{ })format(rowcolumnindex)elseprint("not found"