Hard time catching Environment Exception in Python
Question: I have this simple code to setup a logfile at specific location: (Python
2.7.3)

    
    
    import os, errno
    try:
        CCustomLogger.setup_daemon_logger('TRexServer', "/var/log/trex/trex_daemon_server.log")
    except EnvironmentError, e:
            print "caught some exception...!"
            if e.errno == errno.EACCES: # catching permission denied error
                print "Launching user must have sudo privileges in order to run T-Rex daemon."
            exit(1)
    

However, when I try to run it, I still get the error and can't catch it:

    
    
    Traceback (most recent call last):
      File "trex_daemon_server.py", line 50, in <module>
        handler = logging.FileHandler("/var/log/trex/trex_daemon_server.log")
      File "/usr/lib64/python2.7/logging/__init__.py", line 897, in __init__
        StreamHandler.__init__(self, self._open())
      File "/usr/lib64/python2.7/logging/__init__.py", line 916, in _open
        stream = open(self.baseFilename, self.mode)
    IOError: [Errno 13] Permission denied: '/var/log/trex/trex_daemon_server.log'
    

What's weird here is that even the `some error` print in not printed.

I Googled a little bit and found out that this may be caused by indentation
error ([see here for
example](http://stackoverflow.com/questions/4799974/continue-on-except-of-a-
try-block-in-python)) but I think this isn't it...

What else could be the problem?

Thanks,


Answer: The code appears to be raising `IOError`, not `EnvironmentError`.

