petsc-3.13.6 2020-09-29
Report Typos and Errors

CHKERRQ

Checks error code, if non-zero it calls the error handler and then returns

Synopsis

#include <petscsys.h>
PetscErrorCode CHKERRQ(PetscErrorCode ierr)
Not Collective

Input Parameters

ierr -nonzero error code, see the list of standard error codes in include/petscerror.h

Notes

Once the error handler is called the calling function is then returned from with the given error code.

Experienced users can set the error handler with PetscPushErrorHandler().

CHKERRQ(ierr) is fundamentally a macro replacement for if (ierr) return(PetscError(...,ierr,...));

Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular, it cannot be used in functions which return(void) or any other datatype. In these types of functions, you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or if (ierr) {PetscError(....); return(YourReturnType);} where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.

See Also

PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()

Level

beginner

Location

src/sys/error/../../../include/petscerror.h

Examples

src/sys/classes/viewer/tutorials/ex1.c.html
src/sys/classes/viewer/tutorials/ex2.c.html
src/sys/classes/random/tutorials/ex1.c.html
src/sys/classes/random/tutorials/ex2.c.html
src/sys/tutorials/ex1.c.html
src/sys/tutorials/ex2.c.html
src/sys/tutorials/ex3.c.html
src/sys/tutorials/ex4.c.html
src/sys/tutorials/ex5.c.html
src/sys/tutorials/ex16.c.html
src/sys/tutorials/ex17.c.html

Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages