Reference documentation for deal.II version 9.1.0-pre
exceptions.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2016 - 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/base/config.h>
17 
18 #include <deal.II/lac/exceptions.h>
19 
20 #ifdef DEAL_II_WITH_PETSC
21 # include <petscconf.h>
22 # include <petscsys.h>
23 #endif // DEAL_II_WITH_PETSC
24 
25 DEAL_II_NAMESPACE_OPEN
26 
27 namespace LACExceptions
28 {
29  ExcPETScError::ExcPETScError(const int error_code)
30  : error_code(error_code)
31  {}
32 
33  void
34  ExcPETScError::print_info(std::ostream &out) const
35  {
36  out << "deal.II encountered an error while calling a PETSc function."
37  << std::endl;
38 #ifdef DEAL_II_WITH_PETSC
39  // PetscErrorMessage changes the value in a pointer to refer to a
40  // statically allocated description of the current error message.
41  const char * petsc_message;
42  const PetscErrorCode ierr = PetscErrorMessage(error_code,
43  &petsc_message,
44  /*specific=*/nullptr);
45  if (ierr == 0 && petsc_message != nullptr)
46  {
47  out << "The description of the error provided by PETSc is \""
48  << petsc_message << "\"." << std::endl;
49  }
50  else
51  {
52  out
53  << "PETSc was not able to determine a description for this particular error code."
54  << std::endl;
55  }
56 #endif // DEAL_II_WITH_PETSC
57  out << "The numerical value of the original error code is " << error_code
58  << "." << std::endl;
59  }
60 } // namespace LACExceptions
61 
62 DEAL_II_NAMESPACE_CLOSE