Detailed Description
OCILIB provides two mechanisms for error handling:
- Global error handling through callbacks.
- Contextual thread error handling
Exceptions are raised:
- On Oracle OCI API call error
- On Oracle SQL statement error
- On Internal OCILIB error (type checking, memory allocations ...)
- On Oracle warnings (OCI API or SQL) from v3.5.0 is warnings are enabled
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
- Note:
- The two ways to handle errors are not exclusive and can be mixed.
-
Thread contextual error is also available for single thread based applications
- Oracle Warnings
Oracle warnings are raised through OCI_Error API. Such error handles have their error type property (OCI_ErrorGetType()) set to OCI_ERR_WARNING. Warning handing is disabled by default. To activate/deactivate it, use OCI_EnableWarnings()
- Example with callbacks
- Example with thread context
- Example of warning handling
-
Function Documentation
OCI_EXPORT OCI_Error* OCI_API OCI_GetLastError |
( |
void |
| ) |
|
Retrieve the last error occurred within the last OCILIB call.
- Note:
- OCI_GetLastError() is based on thread context and thus OCILIB must be initialized with the flag OCI_ENV_CONTEXT
Definition at line 1429 of file library.c.
OCI_EXPORT const mtext* OCI_API OCI_ErrorGetString |
( |
OCI_Error * |
err | ) |
|
Retrieve error message from error handle.
- Parameters:
-
Definition at line 154 of file error.c.
OCI_EXPORT unsigned int OCI_API OCI_ErrorGetType |
( |
OCI_Error * |
err | ) |
|
Retrieve the type of error from error handle.
- Parameters:
-
- Note:
- Returns one of the following values:
- OCI_ERR_ORACLE
- OCI_ERR_OCILIB
- OCI_ERR_WARNING
- Returns:
- Object type or OCI_UNKNOWN the input handle is NULL
Definition at line 168 of file error.c.
OCI_EXPORT int OCI_API OCI_ErrorGetOCICode |
( |
OCI_Error * |
err | ) |
|
Retrieve Oracle Error code from error handle.
- Parameters:
-
Definition at line 182 of file error.c.
OCI_EXPORT int OCI_API OCI_ErrorGetInternalCode |
( |
OCI_Error * |
err | ) |
|
Retrieve Internal Error code from error handle.
- Parameters:
-
Definition at line 196 of file error.c.
Retrieve connection handle within the error occurred.
- Parameters:
-
Definition at line 210 of file error.c.
Retrieve statement handle within the error occurred.
- Parameters:
-
- Note:
- If the error occurred outside of a statement context, it returns NULL
Definition at line 224 of file error.c.
OCI_EXPORT unsigned int OCI_API OCI_ErrorGetRow |
( |
OCI_Error * |
err | ) |
|
Return the row index which caused an error during statement execution.
- Parameters:
-
- Warning:
- Row index start at 1.
- Returns:
- 0 is the error is not related to array DML otherwise the index of the given row which caused the error
Definition at line 238 of file error.c.