In article <[EMAIL PROTECTED]>, Fulvio <[EMAIL PROTECTED]> wrote: >*********************** >Your mail has been scanned by InterScan MSS. >*********************** > > >Hello there, > >Simple question : how do I manage errors by the use "try/except" clause. >Example: >If I'd like to catch error coming from a function call that's using IMAP4 >class, which error may raise such class? >In other words I've doubts about which error object I should put after >the "except" statement in order to trap the wanted error. > >Is there, somehow, the way to list the errors from a class or function, prior >digging into the source? > >F >
No. It's an important question. No, there is NOT in general a way to interrogate a class or function to determine the range of exceptions it might throw. Working programmers take a couple of approaches to analyze exceptions: A. Read documentation. Good API documentation must specify exceptions thrown. It's very, *very* rare for Python extensions to document their exceptions accurately. B. Incrementally refine your source. I might write try: do_imap_stuff() except: raise for my first round of coding. Then I exercise a couple of use cases, and reach try: do_imap_stuff() except IOError: handle_this_exception() except ZeroDivisionError: handle_that_exception() except: raise and so on. Exceptions are hard to get right. I keep threatening to write a book on the subject, mostly so I can learn what the correct answers are. -- http://mail.python.org/mailman/listinfo/python-list