Actual source code: ex1.c

  1: static char help[] = "Demonstrates PETSc error handlers.\n";

  3: #include <petscsys.h>

  5: PetscErrorCode CreateError(int n)
  6: {
  7:   PetscCheck(n, PETSC_COMM_WORLD, PETSC_ERR_USER, "Error Created");
  8:   PetscCall(CreateError(n - 1));
  9:   return PETSC_SUCCESS;
 10: }

 12: int main(int argc, char **argv)
 13: {
 14:   PetscFunctionBeginUser;
 15:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
 16:   PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "Demonstrates PETSc Error Handlers\n"));
 17:   PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "The error is a contrived error to test error handling\n"));
 18:   PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT));
 19:   PetscCall(CreateError(5));
 20:   PetscCall(PetscFinalize());
 21:   return 0;
 22: }

 24: /*TEST

 26:  # Testing errors so only look for errors
 27:    test:
 28:      requires: !defined(PETSCTEST_VALGRIND) !defined(PETSC_HAVE_SANITIZER)
 29:      args: -petsc_ci_portable_error_output -error_output_stdout
 30:      nsize: {{1 2 3}}
 31:      filter: grep -E "(PETSC ERROR)" | egrep "(Error Created|CreateError\(\)|main\(\))"

 33: TEST*/