warnings functions can signal conditions with raise user-defined exceptions can also signal nonerror conditions for instancea search routine can be coded to raise an exception when match is found instead of returning status flag for the caller to interpret in the followingthe try/except/else exception handler does the work of an if/else return-value testerclass found(exception)pass def searcher()if success raise found(elsereturn raise exceptions instead of returning flags trysearcher(except foundsuccess elsefailure exception if item was found else returnednot found more generallysuch coding structure may also be useful for any function that cannot return sentinel value to designate success or failure in widely applicable functionfor instanceif all objects are potentially valid return valuesit' impossible for any return value to signal failure condition exceptions provide way to signal results without return valueclass failure(exception)pass def searcher()if success return founditem elseraise failure(tryitem searcher(except failurenot found elseuse item here because python is dynamically typed and polymorphic to the coreexceptionsrather than sentinel return valuesare the generally preferred way to signal such conditions exception idioms