1e5c89e4eSSatish Balay /* 2e5c89e4eSSatish Balay The default error handlers and code that allows one to change 3e5c89e4eSSatish Balay error handlers. 4e5c89e4eSSatish Balay */ 5c6db04a5SJed Brown #include <petscsys.h> /*I "petscsys.h" I*/ 6e5c89e4eSSatish Balay 7e5c89e4eSSatish Balay /*@C 8e5c89e4eSSatish Balay PetscAbortErrorHandler - Error handler that calls abort on error. 9e5c89e4eSSatish Balay This routine is very useful when running in the debugger, because the 106e25c4a1SBarry Smith user can look directly at the stack frames and the variables where the error occurred 11e5c89e4eSSatish Balay 12cc4c1da9SBarry Smith Not Collective, No Fortran Support 13e5c89e4eSSatish Balay 14e5c89e4eSSatish Balay Input Parameters: 15e32f2f54SBarry Smith + comm - communicator over which error occurred 166e25c4a1SBarry Smith . line - the line number of the error (usually indicated by `__LINE__` in the calling routine) 176e25c4a1SBarry Smith . fun - the function name of the calling routine 186e25c4a1SBarry Smith . file - the file in which the error was detected (usually indicated by `__FILE__` in the calling routine) 196e25c4a1SBarry Smith . mess - an error text string, usually this is just printed to the screen 20e5c89e4eSSatish Balay . n - the generic error number 216e25c4a1SBarry Smith . p - `PETSC_ERROR_INITIAL` indicates this is the first time the error handler is being called while `PETSC_ERROR_REPEAT` indicates it was previously called 22e5c89e4eSSatish Balay - ctx - error handler context 23e5c89e4eSSatish Balay 24e5c89e4eSSatish Balay Options Database Keys: 25e5c89e4eSSatish Balay + -on_error_abort - Activates aborting when an error is encountered 266e25c4a1SBarry Smith - -start_in_debugger [noxterm,lldb or gdb] [-display name] - Starts all processes in the debugger and uses `PetscAbortErrorHandler()`. By default on Linux the 276e25c4a1SBarry Smith debugger is gdb and on macOS it is lldb 28e5c89e4eSSatish Balay 29e5c89e4eSSatish Balay Level: developer 30e5c89e4eSSatish Balay 31e5c89e4eSSatish Balay Notes: 32baca6076SPierre Jolivet Users do not directly employ this routine 33e5c89e4eSSatish Balay 34811af0c4SBarry Smith Use `PetscPushErrorHandler()` to set the desired error handler. The 35811af0c4SBarry Smith currently available PETSc error handlers include `PetscTraceBackErrorHandler()`, 36811af0c4SBarry Smith `PetscAttachDebuggerErrorHandler()`, and `PetscAbortErrorHandler()`. 37e5c89e4eSSatish Balay 38db781477SPatrick Sanan .seealso: `PetscError()`, `PetscPushErrorHandler()`, `PetscPopErrorHander()`, `PetscTraceBackErrorHandler()`, 396e25c4a1SBarry Smith `PetscAttachDebuggerErrorHandler()`, `PetscMPIAbortErrorHandler()`, `PetscReturnErrorHandler()`, `PetscEmacsClientErrorHandler()`, 406e25c4a1SBarry Smith `PetscErrorType`, `PETSC_ERROR_INITIAL`, `PETSC_ERROR_REPEAT`, `PetscErrorCode` 41e5c89e4eSSatish Balay @*/ 42d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscAbortErrorHandler(MPI_Comm comm, int line, const char *fun, const char *file, PetscErrorCode n, PetscErrorType p, const char *mess, void *ctx) 43d71ae5a4SJacob Faibussowitsch { 448ff741acSBarry Smith size_t len; 458ff741acSBarry Smith 46e5c89e4eSSatish Balay PetscFunctionBegin; 4710450e9eSJacob Faibussowitsch (void)comm; 4810450e9eSJacob Faibussowitsch (void)p; 4910450e9eSJacob Faibussowitsch (void)ctx; 50*dd460d27SBarry Smith (void)n; 518ff741acSBarry Smith (void)PetscStrlen(fun, &len); 528ff741acSBarry Smith if (len) { 53*dd460d27SBarry Smith (void)(*PetscErrorPrintf)("PetscAbortErrorHandler: %s() at %s:%d %s\n To prevent termination, change the error handler using PetscPushErrorHandler()\n", fun, file, line, mess); 548ff741acSBarry Smith } else { 55*dd460d27SBarry Smith (void)(*PetscErrorPrintf)("PetscAbortErrorHandler: %s\n To prevent termination, change the error handler using PetscPushErrorHandler()\n", mess); 568ff741acSBarry Smith } 57e5c89e4eSSatish Balay abort(); 583ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 59e5c89e4eSSatish Balay } 60