Page 153 -
P. 153

persistence


           Knowing the type of error is not enough


           When a file I/O error occurs, your code displays a generic “File Error”
           message. This is too generic. How do you know what actually happened?






                                                It could be that the                Yeah, or it could be
                                                file can be opened but              a permission error, or
              Maybe the problem                  not written to?                    maybe your disk is full?
              is that you can’t open
              the file?
































           Who knows?

           It turns out that the Python interpreter knows…and it will give up the details
           if only you’d ask.

           When an error occurs at runtime, Python raises an exception of the specific
           type (such as IOError, ValueError, and so on). Additionally, Python
           creates an exception object that is passed as an argument to your except
           suite.


           Let’s use IDLE to see how this works.

                                                                                      you are here 4    117
   148   149   150   151   152   153   154   155   156   157   158