www.mooseframework.org
MooseError.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "MooseError.h"
16 #include "MooseUtils.h"
17 
18 namespace moose
19 {
20 namespace internal
21 {
22 
23 std::string
24 mooseMsgFmt(const std::string & msg, const std::string & title, const std::string & color)
25 {
26  std::ostringstream oss;
27  oss << "\n\n" << color << "\n\n" << title << "\n" << msg << COLOR_DEFAULT << "\n\n";
28  return oss.str();
29 }
30 
31 static Threads::spin_mutex moose_err_lock;
32 
33 [[noreturn]] void
34 mooseErrorRaw(std::string msg, const std::string prefix)
35 {
36  msg = mooseMsgFmt(msg, "*** ERROR ***", COLOR_RED);
37 
39  {
40  if (!prefix.empty())
41  MooseUtils::indentMessage(prefix, msg);
42  throw std::runtime_error(msg);
43  }
44 
45  std::ostringstream oss;
46  oss << msg << "\n";
47 
48  // this independent flush of the partial error message (i.e. without the
49  // trace) is here because trace retrieval can be slow in some
50  // circumstances, and we want to get the error message out ASAP.
51  msg = oss.str();
52  if (!prefix.empty())
53  MooseUtils::indentMessage(prefix, msg);
54  {
55  Threads::spin_mutex::scoped_lock lock(moose_err_lock);
56  Moose::err << msg << std::flush;
57  }
58 
59  oss.str("");
60  if (libMesh::global_n_processors() == 1)
61  print_trace(oss);
62 
63  msg = oss.str();
64  if (!prefix.empty())
65  MooseUtils::indentMessage(prefix, msg);
66 
67  Threads::spin_mutex::scoped_lock lock(moose_err_lock);
68 
69  Moose::err << msg << std::flush;
70 
71  if (libMesh::global_n_processors() > 1)
72  libMesh::write_traceout();
73 
74  MOOSE_ABORT;
75 }
76 
77 void
78 mooseStreamAll(std::ostringstream &)
79 {
80 }
81 
82 } // namespace internal
83 } // namespace moose
void mooseStreamAll(std::ostringstream &ss)
Definition: MooseError.C:78
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:438
static Threads::spin_mutex moose_err_lock
Definition: MooseError.C:31
void mooseErrorRaw(std::string msg, const std::string prefix="")
Definition: MooseError.C:34
bool _throw_on_error
Variable to turn on exceptions during mooseError() and mooseWarning(), should only be used with MOOSE...
Definition: Moose.C:1286
std::string mooseMsgFmt(const std::string &msg, const std::string &title, const std::string &color)
Definition: MooseError.C:24