this module houses the gdal srs exception objects and the checkerr routine which checks the status code returned by gdalogr methods gdal srs exceptions gdalogr error checking codes and routine ogr error codes cpl error codes https gdal orgapicpl htmlcplerrorh check the given cplogrerr and raise an exception where appropriate gdal srs exceptions gdal ogr error checking codes and routine ogr error codes cpl error codes https gdal org api cpl html cpl error h check the given cpl ogrerr and raise an exception where appropriate
class GDALException(Exception):
    pass


class SRSException(Exception):
    pass





OGRERR_DICT = {
    1: (GDALException, "Not enough data."),
    2: (GDALException, "Not enough memory."),
    3: (GDALException, "Unsupported geometry type."),
    4: (GDALException, "Unsupported operation."),
    5: (GDALException, "Corrupt data."),
    6: (GDALException, "OGR failure."),
    7: (SRSException, "Unsupported SRS."),
    8: (GDALException, "Invalid handle."),
}



CPLERR_DICT = {
    1: (GDALException, "AppDefined"),
    2: (GDALException, "OutOfMemory"),
    3: (GDALException, "FileIO"),
    4: (GDALException, "OpenFailed"),
    5: (GDALException, "IllegalArg"),
    6: (GDALException, "NotSupported"),
    7: (GDALException, "AssertionFailed"),
    8: (GDALException, "NoWriteAccess"),
    9: (GDALException, "UserInterrupt"),
    10: (GDALException, "ObjectNull"),
}

ERR_NONE = 0


def check_err(code, cpl=False):
    
    err_dict = CPLERR_DICT if cpl else OGRERR_DICT

    if code == ERR_NONE:
        return
    elif code in err_dict:
        e, msg = err_dict[code]
        raise e(msg)
    else:
        raise GDALException('Unknown error code: "%s"' % code)