xref: /petsc/src/sys/error/errstop.c (revision 0619917b5a674bb687c64e7daba2ab22be99af31)
1 
2 #include <petscsys.h> /*I "petscsys.h" I*/
3 #include "err.h"
4 
5 /*@C
6   PetscMPIAbortErrorHandler - Calls PETSCABORT and exits.
7 
8   Not Collective
9 
10   Input Parameters:
11 + comm - communicator over which error occurred
12 . line - the line number of the error (indicated by __LINE__)
13 . fun  - the function name
14 . file - the file in which the error was detected (indicated by __FILE__)
15 . mess - an error text string, usually just printed to the screen
16 . n    - the generic error number
17 . p    - `PETSC_ERROR_INITIAL` if error just detected, otherwise `PETSC_ERROR_REPEAT`
18 - ctx  - error handler context
19 
20   Level: developer
21 
22   Note:
23   Users do not directly call this routine
24 
25   Use `PetscPushErrorHandler()` to set the desired error handler.  The
26   currently available PETSc error handlers include `PetscTraceBackErrorHandler()`,
27   `PetscMPIAbortErrorHandler()`, `PetscAttachDebuggerErrorHandler()`, and `PetscAbortErrorHandler()`.
28 
29 .seealso: `PetscError()`, `PetscPushErrorHandler()`, `PetscPopErrorHandler()`, `PetscAttachDebuggerErrorHandler()`,
30           `PetscAbortErrorHandler()`, `PetscTraceBackErrorHandler()`, `PetscEmacsClientErrorHandler()`, `PetscReturnErrorHandler()`
31  @*/
32 PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm comm, int line, const char *fun, const char *file, PetscErrorCode n, PetscErrorType p, const char *mess, void *ctx)
33 {
34   PetscErrorCode ierr;
35 
36   PetscFunctionBegin;
37   if (!mess) mess = " ";
38 
39   if (n == PETSC_ERR_MEM || n == PETSC_ERR_MEM_LEAK) ierr = PetscErrorMemoryMessage(n);
40   else if (n == PETSC_ERR_SUP) {
41     ierr = (*PetscErrorPrintf)("%s() at %s:%d\n", fun, file, line);
42     ierr = (*PetscErrorPrintf)("No support for this operation for this object type!\n");
43     ierr = (*PetscErrorPrintf)("%s\n", mess);
44   } else if (n == PETSC_ERR_SIG) ierr = (*PetscErrorPrintf)("%s() at %s:%d %s\n", fun, file, line, mess);
45   else ierr = (*PetscErrorPrintf)("%s() at %s:%d\n    %s\n", fun, file, line, mess);
46 
47   (void)ierr;
48   PETSCABORT(PETSC_COMM_WORLD, n);
49   PetscFunctionReturn(PETSC_SUCCESS);
50 }
51