www.mooseframework.org
MooseError.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "MooseError.h"
11 #include "MooseUtils.h"
12 #include "MooseVariable.h"
13 
14 #include "libmesh/string_to_enum.h"
15 
16 namespace moose
17 {
18 namespace internal
19 {
20 
21 std::string
23 {
24  std::stringstream ss;
25  ss << libMesh::Utility::enum_to_string<FEFamily>(var1.feType().family) << ",ORDER"
26  << var1.feType().order
27  << " != " << libMesh::Utility::enum_to_string<FEFamily>(var2.feType().family) << ",ORDER"
28  << var2.feType().order;
29  return ss.str();
30 }
31 
32 std::string
33 mooseMsgFmt(const std::string & msg, const std::string & title, const std::string & color)
34 {
35  std::ostringstream oss;
36  oss << "\n\n" << color << "\n\n" << title << "\n" << msg << COLOR_DEFAULT << "\n\n";
37  return oss.str();
38 }
39 
40 static Threads::spin_mutex moose_err_lock;
41 
42 [[noreturn]] void
43 mooseErrorRaw(std::string msg, const std::string prefix)
44 {
45  msg = mooseMsgFmt(msg, "*** ERROR ***", COLOR_RED);
46 
48  {
49  if (!prefix.empty())
50  MooseUtils::indentMessage(prefix, msg);
51  throw std::runtime_error(msg);
52  }
53 
54  std::ostringstream oss;
55  oss << msg << "\n";
56 
57  // this independent flush of the partial error message (i.e. without the
58  // trace) is here because trace retrieval can be slow in some
59  // circumstances, and we want to get the error message out ASAP.
60  msg = oss.str();
61  if (!prefix.empty())
62  MooseUtils::indentMessage(prefix, msg);
63  {
64  Threads::spin_mutex::scoped_lock lock(moose_err_lock);
65  Moose::err << msg << std::flush;
66  }
67 
68  oss.str("");
69  if (libMesh::global_n_processors() == 1)
70  print_trace(oss);
71 
72  msg = oss.str();
73  if (!prefix.empty())
74  MooseUtils::indentMessage(prefix, msg);
75 
76  Threads::spin_mutex::scoped_lock lock(moose_err_lock);
77 
78  Moose::err << msg << std::flush;
79 
80  if (libMesh::global_n_processors() > 1)
81  libMesh::write_traceout();
82 
83  MOOSE_ABORT;
84 }
85 
86 void
87 mooseStreamAll(std::ostringstream &)
88 {
89 }
90 
91 } // namespace internal
92 } // namespace moose
void mooseStreamAll(std::ostringstream &ss)
All of the following are not meant to be called directly - they are called by the normal macros (moos...
Definition: MooseError.C:87
std::string incompatVarMsg(MooseVariableFEBase &var1, MooseVariableFEBase &var2)
Builds and returns a string of the form:
Definition: MooseError.C:22
void indentMessage(const std::string &prefix, std::string &message, const char *color=COLOR_CYAN)
Indents the supplied message given the prefix and color.
Definition: MooseUtils.C:431
const FEType & feType() const
Get the type of finite element object.
static Threads::spin_mutex moose_err_lock
Definition: MooseError.C:40
void mooseErrorRaw(std::string msg, const std::string prefix="")
Definition: MooseError.C:43
bool _throw_on_error
Variable to turn on exceptions during mooseError() and mooseWarning(), should only be used with MOOSE...
Definition: Moose.C:574
std::string mooseMsgFmt(const std::string &msg, const std::string &title, const std::string &color)
Definition: MooseError.C:33