R: [Gdal-dev] Error messages

Frank Warmerdam warmerdam at pobox.com
Sun Mar 2 12:24:34 EST 2003


>>>In C or C++ call "GDALSetErrorHandler(
>>
>>CPLQuietErrorHandler );".
>>
>>is there any way to do it from python?
>>i don't need to attach an handler, just to silence
>>the errors.


Alessandro,

I have added PushErrorHandler(), PopErrorHandler(), and Error() methods
in the "gdal" module.  The PushErrorHandler() takes either the name of a
well known error handler, or a Python function to invoke.

For example:

import gdal

def MyHandler( err_class, err_code, msg ):
     print err_class, err_code, msg

gdal.Error( msg = 'Test Message' )

gdal.PushErrorHandler( "CPLQuietErrorHandler" )

gdal.Error( msg = 'Test Message 2' )

gdal.PushErrorHandler( MyHandler )

gdal.Error( msg = 'Test Message 3' )
gdal.Debug( 'test1', 'message' )

gdal.PopErrorHandler()

gdal.Error( msg = 'Test Message 4' )

gdal.PopErrorHandler()

gdal.Error( msg = 'Test Message 5' )


Produces:

warmerda at gdal2200[40]% ./test1.py
ERROR 1: Test Message
3 1 Test Message 3
1 0 Sun Mar  2 12:23:26 2003: test1: message
ERROR 1: Test Message 5

As you can see, "gdal.PushErrorHandler( 'CPLQuietHandler' )" should be
sufficient for your needs.  The error handler mechanism can also be
used to redirect debug output.

Best regards,

-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent





More information about the Gdal-dev mailing list