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 
19 namespace internal
20 {
21 
22 std::string
24 {
25  std::stringstream ss;
26  ss << libMesh::Utility::enum_to_string<FEFamily>(var1.feType().family) << ",ORDER"
27  << var1.feType().order
28  << " != " << libMesh::Utility::enum_to_string<FEFamily>(var2.feType().family) << ",ORDER"
29  << var2.feType().order;
30  return ss.str();
31 }
32 
33 std::string
34 mooseMsgFmt(const std::string & msg, const std::string & title, const std::string & color)
35 {
36  std::ostringstream oss;
37  oss << "\n" << color << "\n" << title << "\n" << msg << COLOR_DEFAULT << "\n";
38  return oss.str();
39 }
40 
41 static Threads::spin_mutex moose_err_lock;
42 
43 [[noreturn]] void
44 mooseErrorRaw(std::string msg, const std::string prefix)
45 {
46  msg = mooseMsgFmt(msg, "*** ERROR ***", COLOR_RED);
47 
49  {
50  if (!prefix.empty())
51  MooseUtils::indentMessage(prefix, msg);
52  throw std::runtime_error(msg);
53  }
54 
55  std::ostringstream oss;
56  oss << msg << "\n";
57 
58  // this independent flush of the partial error message (i.e. without the
59  // trace) is here because trace retrieval can be slow in some
60  // circumstances, and we want to get the error message out ASAP.
61  msg = oss.str();
62  if (!prefix.empty())
63  MooseUtils::indentMessage(prefix, msg);
64  {
65  Threads::spin_mutex::scoped_lock lock(moose_err_lock);
66  Moose::err << msg << std::flush;
67  }
68 
69  oss.str("");
70  if (Moose::show_trace && libMesh::global_n_processors() == 1)
71  print_trace(oss);
72 
73  msg = oss.str();
74  if (!prefix.empty())
75  MooseUtils::indentMessage(prefix, msg);
76 
77  Threads::spin_mutex::scoped_lock lock(moose_err_lock);
78 
79  Moose::err << msg << std::flush;
80 
81  if (libMesh::global_n_processors() > 1)
82  libMesh::write_traceout();
83 
84  MOOSE_ABORT;
85 }
86 
87 void
88 mooseStreamAll(std::ostringstream &)
89 {
90 }
91 
92 } // namespace internal
93 } // namespace moose
MooseVariableFEBase
Definition: MooseVariableFEBase.h:27
moose::internal::mooseStreamAll
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:88
moose::internal::moose_err_lock
static Threads::spin_mutex moose_err_lock
Definition: MooseError.C:41
MooseVariableBase::feType
const FEType & feType() const
Get the type of finite element object.
Definition: MooseVariableBase.h:53
MooseVariable.h
Moose::_throw_on_error
bool _throw_on_error
Variable to turn on exceptions during mooseError() and mooseWarning(), should only be used with MOOSE...
Definition: Moose.C:571
moose
Definition: MooseError.h:100
moose::internal::incompatVarMsg
std::string incompatVarMsg(MooseVariableFEBase &var1, MooseVariableFEBase &var2)
Builds and returns a string of the form:
Definition: MooseError.C:23
MooseError.h
Moose::show_trace
bool show_trace
Set to true (the default) to print the stack trace with error and warning messages - false to omit it...
Definition: Moose.C:572
MooseUtils::indentMessage
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:443
moose::internal::mooseMsgFmt
std::string mooseMsgFmt(const std::string &msg, const std::string &title, const std::string &color)
Definition: MooseError.C:34
moose::internal::mooseErrorRaw
void mooseErrorRaw(std::string msg, const std::string prefix="")
Definition: MooseError.C:44
MooseUtils.h