Reference documentation for deal.II version 8.5.1
exceptions.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2016 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 at
12 // the top level of the deal.II distribution.
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 #include <petscerror.h>
24 #endif // DEAL_II_WITH_PETSC
25 
26 DEAL_II_NAMESPACE_OPEN
27 
28 namespace LACExceptions
29 {
30  ExcPETScError::ExcPETScError (const int error_code)
31  :
32  error_code (error_code)
33  {}
34 
35  void ExcPETScError::print_info (std::ostream &out) const
36  {
37  out << "deal.II encountered an error while calling a PETSc function."
38  << std::endl;
39 #ifdef DEAL_II_WITH_PETSC
40  // PetscErrorMessage changes the value in a pointer to refer to a
41  // statically allocated description of the current error message.
42  const char *petsc_message;
43  const PetscErrorCode ierr = PetscErrorMessage (error_code, &petsc_message,
44  /*specific=*/NULL);
45  if (ierr == 0 && petsc_message != NULL)
46  {
47  out << "The description of the error provided by PETSc is \""
48  << petsc_message
49  << "\"."
50  << std::endl;
51  }
52  else
53  {
54  out << "PETSc was not able to determine a description for this particular error code."
55  << std::endl;
56  }
57 #endif // DEAL_II_WITH_PETSC
58  out << "The numerical value of the original error code is "
59  << error_code
60  << "."
61  << std::endl;
62  }
63 } // namespace LACExceptions
64 
65 DEAL_II_NAMESPACE_CLOSE