xref: /petsc/src/sys/error/errabort.c (revision 6e25c4a1c90824faf3d538972096603dc1ddc238)
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
10*6e25c4a1SBarry Smith   user can look directly at the stack frames and the variables where the error occurred
11e5c89e4eSSatish Balay 
12e5c89e4eSSatish Balay   Not Collective
13e5c89e4eSSatish Balay 
14e5c89e4eSSatish Balay   Input Parameters:
15e32f2f54SBarry Smith + comm - communicator over which error occurred
16*6e25c4a1SBarry Smith . line - the line number of the error (usually indicated by `__LINE__` in the calling routine)
17*6e25c4a1SBarry Smith . fun  - the function name of the calling routine
18*6e25c4a1SBarry Smith . file - the file in which the error was detected (usually indicated by `__FILE__` in the calling routine)
19*6e25c4a1SBarry Smith . mess - an error text string, usually this is just printed to the screen
20e5c89e4eSSatish Balay . n    - the generic error number
21*6e25c4a1SBarry 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
26*6e25c4a1SBarry Smith - -start_in_debugger [noxterm,lldb or gdb] [-display name] - Starts all processes in the debugger and uses `PetscAbortErrorHandler()`. By default on Linux the
27*6e25c4a1SBarry 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()`,
39*6e25c4a1SBarry Smith           `PetscAttachDebuggerErrorHandler()`, `PetscMPIAbortErrorHandler()`, `PetscReturnErrorHandler()`, `PetscEmacsClientErrorHandler()`,
40*6e25c4a1SBarry 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 {
44e5c89e4eSSatish Balay   PetscFunctionBegin;
4510450e9eSJacob Faibussowitsch   (void)comm;
4610450e9eSJacob Faibussowitsch   (void)p;
4710450e9eSJacob Faibussowitsch   (void)ctx;
483ba16761SJacob Faibussowitsch   n = (*PetscErrorPrintf)("PetscAbortErrorHandler: %s() at %s:%d %s\n  To prevent termination, change the error handler using PetscPushErrorHandler()\n", fun, file, line, mess);
49e5c89e4eSSatish Balay   abort();
502b7c89d8SPierre Jolivet   (void)n;
513ba16761SJacob Faibussowitsch   PetscFunctionReturn(PETSC_SUCCESS);
52e5c89e4eSSatish Balay }
53