There are some python 'only' rules stated at the 'Python Gotchas' page.
At the beginning they state that:
By default, the GDAL and OGR Python bindings do not raise exceptions when errors occur. Instead they return an error value such as None and write an error message to sys.stdout.
So first enable the use of exceptions, by issuing
gdal.UseExceptions() somewhere in the beginning of your script. And secondly catch if any exceptions and do whatever you want with them (including nothing)
gdal.UseExceptions() # Enable errors
except RuntimeError: # <- Check first what exception is being thrown
If you're curious here's a link from python's wiki where they describe the methods of exception handling.
As far as I can tell, using gdal.UseExceptions() will normalize the behaviour of all the methods in the gdal lib, by making those methods to use the Python Exceptions. If you really want to ignore all exceptions put the problematic part of your code inside a try/except block eg.:
a = 0
b = 1
c = b/a # <- I just divided by zero.
print "Everything is ok" # <- but Everything is Ok.
# If you really want to be silent replace with pass
'Nothing to see here'
Just be careful, because that way when an exception happens, your script will silently break from the procedure without any indication of what went wrong.
Also I want to point a couple of things as well:
- If you're opt to go that way, you're responsible if your program does. You're choosing to turn a blind eye at any errors that come in your way.
- If you catch ALL the exceptions, you will also catch the 'KeyboardInterrupt' exception as well. No more
ctrl-c (if you're inside a try/except block).
- Your code at some point is encountering a processing error. Since you're not using gdal.UseExceptions() you're experiencing that error as a sys.stdout response. Use a try/except block at that point to plug that hole.