PetscCallCXXAbort#

Like PetscCallCXX() but calls MPI_Abort() instead of returning an error-code

Synopsis#

#include <petscerror.h>
void PetscCallCXXAbort(MPI_Comm comm, ...) noexcept;

Collective; No Fortran Support

Input Parameters#

  • comm - The MPI communicator to abort on

  • VA_ARGS - An arbitrary expression

Notes#

This macro may be used to check C++ expressions for exceptions in cases where you cannot return an error code. This includes constructors, destructors, copy/move assignment functions or constructors among others.

If an exception is caught, the macro calls SETERRABORT() on comm. The exception must derive from std::exception in order to be caught.

If the routine can return an error-code it is highly advised to use PetscCallCXX() instead.

See PetscCallCXX() for additional discussion.

Example Usage#

  class Foo
  {
    std::vector<int> data_;

  public:
    // normally std::vector::reserve() may raise an exception, but since we handle it with
    // PetscCallCXXAbort() we may mark this routine as noexcept!
    Foo() noexcept
    {
      PetscCallCXXAbort(PETSC_COMM_SELF, data_.reserve(10));
    }
  };

  std::vector<int> bar()
  {
    std::vector<int> v;

    PetscFunctionBegin;
    // OK!
    PetscCallCXXAbort(PETSC_COMM_SELF, v.emplace_back(1));
    PetscFunctionReturn(v);
  }

  PetscErrorCode baz()
  {
    std::vector<int> v;

    PetscFunctionBegin;
    // WRONG! baz() returns a PetscErrorCode, prefer PetscCallCXX() instead
    PetscCallCXXAbort(PETSC_COMM_SELF, v.emplace_back(1));
    PetscFunctionReturn(PETSC_SUCCESS);
  }

See Also#

PetscCallCXX(), SETERRABORT(), PetscCallAbort()

Level#

beginner

Location#

include/petscerror.h


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