Exceptions are raised:
If an error handler was provided to OCI_Initialize(), when an error occurs, the library generates an OCI_Error handle and pass it to the error handler.
In order to use the thread contextual error handling, you must call OCI_Initialize() with the flag OCI_ENV_CONTEXT for the mode parameter. When activated, error handles are stored per thread and the last error within a thread can be retrieved with OCI_GetLastError()
Exception properties are accessible through a set of functions
Thread contextual error is also available for single thread based applications
#include "ocilib.h" void err_handler(OCI_Error *err) { printf( "code : ORA-%05i\n" "msg : %s\n" "sql : %s\n", OCI_ErrorGetOCICode(err), OCI_ErrorGetString(err), OCI_GetSql(OCI_ErrorGetStatement(err)) ); } int main(void) { OCI_Connection *cn; if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("wrong_db", "wrong_usr", "wrong_pwd", OCI_SESSION_DEFAULT); /* ... application code here ... */ OCI_Cleanup(); return EXIT_SUCCESS; }
#include "ocilib.h" int main(void) { OCI_Connection *cn; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_CONTEXT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("wrong_db", "wrong_usr", "wrong_pwd", OCI_SESSION_DEFAULT); if (cn == NULL) { OCI_Error *err = OCI_GetLastError(); printf("errcode %d, errmsg %s", OCI_ErrorGetOCICode(err), OCI_ErrorGetString(err)); } OCI_Cleanup(); return EXIT_SUCCESS; }
Functions | |
OCI_EXPORT OCI_Error *OCI_API | OCI_GetLastError (void) |
Retrieve the last error occurred within the last OCILIB call. | |
OCI_EXPORT const mtext *OCI_API | OCI_ErrorGetString (OCI_Error *err) |
Retrieve error message from error handle. | |
OCI_EXPORT unsigned int OCI_API | OCI_ErrorGetType (OCI_Error *err) |
Retrieve the type of error from error handle. | |
OCI_EXPORT int OCI_API | OCI_ErrorGetOCICode (OCI_Error *err) |
Retrieve Oracle Error code from error handle. | |
OCI_EXPORT int OCI_API | OCI_ErrorGetInternalCode (OCI_Error *err) |
Retrieve Internal Error code from error handle. | |
OCI_EXPORT OCI_Connection *OCI_API | OCI_ErrorGetConnection (OCI_Error *err) |
Retrieve connection handle within the error occurred. | |
OCI_EXPORT OCI_Statement *OCI_API | OCI_ErrorGetStatement (OCI_Error *err) |
Retrieve statement handle within the error occured. | |
OCI_EXPORT unsigned int OCI_API | OCI_ErrorGetRow (OCI_Error *err) |
Return the row index which caused an error during statement execution. |
OCI_EXPORT OCI_Connection* OCI_API OCI_ErrorGetConnection | ( | OCI_Error * | err | ) |
Retrieve connection handle within the error occurred.
err | - Error handle |
Definition at line 169 of file error.c.
References OCI_Error::con.
OCI_EXPORT int OCI_API OCI_ErrorGetInternalCode | ( | OCI_Error * | err | ) |
Retrieve Internal Error code from error handle.
err | - Error handle |
Definition at line 158 of file error.c.
References OCI_Error::icode.
OCI_EXPORT int OCI_API OCI_ErrorGetOCICode | ( | OCI_Error * | err | ) |
Retrieve Oracle Error code from error handle.
err | - Error handle |
Definition at line 147 of file error.c.
References OCI_Error::ocode.
OCI_EXPORT unsigned int OCI_API OCI_ErrorGetRow | ( | OCI_Error * | err | ) |
Return the row index which caused an error during statement execution.
err | - Error handle |
Definition at line 191 of file error.c.
References OCI_Error::row.
OCI_EXPORT OCI_Statement* OCI_API OCI_ErrorGetStatement | ( | OCI_Error * | err | ) |
Retrieve statement handle within the error occured.
err | - Error handle |
Definition at line 180 of file error.c.
References OCI_Error::stmt.
OCI_EXPORT const mtext* OCI_API OCI_ErrorGetString | ( | OCI_Error * | err | ) |
Retrieve error message from error handle.
err | - Error handle |
Definition at line 125 of file error.c.
References OCI_Error::str.
OCI_EXPORT unsigned int OCI_API OCI_ErrorGetType | ( | OCI_Error * | err | ) |
Retrieve the type of error from error handle.
err | - Error handle |
Definition at line 136 of file error.c.
References OCI_Error::type.
OCI_EXPORT OCI_Error* OCI_API OCI_GetLastError | ( | void | ) |
Retrieve the last error occurred within the last OCILIB call.
Definition at line 1256 of file library.c.
References OCI_Error::raise.