PetscCallVoid#

Like PetscCall() but for use in functions that return void

Synopsis#

#include <petscerror.h>
void PetscCallVoid(PetscFunction(args))

Not Collective; No Fortran Support

Input Parameter#

  • PetscFunction - any PETSc function that returns an error code

Example Usage#

  void foo()
  {
    KSP ksp;

    PetscFunctionBeginUser;
    // OK, properly handles PETSc error codes
    PetscCallVoid(KSPCreate(PETSC_COMM_WORLD, &ksp));
    PetscFunctionReturnVoid();
  }

  PetscErrorCode bar()
  {
    KSP ksp;

    PetscFunctionBeginUser;
    // ERROR, Non-void function 'bar' should return a value
    PetscCallVoid(KSPCreate(PETSC_COMM_WORLD, &ksp));
    // OK, returning PetscErrorCode
    PetscCall(KSPCreate(PETSC_COMM_WORLD, &ksp));
    PetscFunctionReturn(PETSC_SUCCESS);
  }

Notes#

Has identical usage to PetscCall(), except that it returns void on error instead of a PetscErrorCode. See PetscCall() for more detailed discussion.

Note that users should prefer PetscCallAbort() to this routine. While this routine does “handle” errors by returning from the enclosing function, it effectively gobbles the error. Since the enclosing function itself returns void, its callers have no way of knowing that the routine returned early due to an error. PetscCallAbort() at least ensures that the program crashes gracefully.

See Also#

PetscCall(), PetscErrorCode, PetscCallAbort(), PetscCallNull()

Level#

beginner

Location#

include/petscerror.h


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