| 202 | /************************************************************************/ |
| 203 | |
| 204 | static void ApplyErrorHandler(CPLErrorContext *psCtx, CPLErr eErrClass, |
| 205 | CPLErrorNum err_no, const char *pszMessage) |
| 206 | { |
| 207 | bool bProcessed = false; |
| 208 | |
| 209 | if (psCtx->psHandlerStack != nullptr) |
| 210 | { |
| 211 | // iterate through the threadlocal handler stack |
| 212 | if ((eErrClass != CE_Debug) || psCtx->psHandlerStack->bCatchDebug) |
| 213 | { |
| 214 | // call the error handler |
| 215 | CPLErrorHandlerNode *psNewCurNode = psCtx->psHandlerStack; |
| 216 | psCtx->psHandlerStack->pfnHandler(eErrClass, err_no, pszMessage); |
| 217 | if (psNewCurNode != psCtx->psHandlerStack) |
| 218 | { |
| 219 | fprintf(stderr, "ApplyErrorHandler() has detected that a " |
| 220 | "previous error handler messed up with the " |
| 221 | "error stack. Chaos guaranteed!\n"); |
| 222 | } |
| 223 | bProcessed = true; |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | // need to iterate to a parent handler for debug messages |
| 228 | CPLErrorHandlerNode *psNode = psCtx->psHandlerStack->psNext; |
| 229 | while (psNode != nullptr) |
| 230 | { |
| 231 | if (psNode->bCatchDebug) |
| 232 | { |
| 233 | CPLErrorHandlerNode *psBackupCurNode = |
| 234 | psCtx->psHandlerStack; |
| 235 | psCtx->psHandlerStack = psNode; |
| 236 | CPLErrorHandlerNode *psNewCurNode = psCtx->psHandlerStack; |
| 237 | psNode->pfnHandler(eErrClass, err_no, pszMessage); |
| 238 | // cppcheck-suppress knownConditionTrueFalse |
| 239 | if (psNewCurNode != psCtx->psHandlerStack) |
| 240 | { |
| 241 | fprintf(stderr, |
| 242 | "ApplyErrorHandler() has detected that a " |
| 243 | "previous error handler messed up with the " |
| 244 | "error stack. Chaos guaranteed!\n"); |
| 245 | } |
| 246 | psCtx->psHandlerStack = psBackupCurNode; |
| 247 | bProcessed = true; |
| 248 | break; |
| 249 | } |
| 250 | psNode = psNode->psNext; |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | if (!bProcessed) |
| 256 | { |
| 257 | // hit the global error handler |
| 258 | CPLMutexHolderD(&hErrorMutex); |
| 259 | if ((eErrClass != CE_Debug) || gbCatchDebug) |
| 260 | { |
| 261 | if (pfnErrorHandler != nullptr) |
no outgoing calls
no test coverage detected