Cantera
Install
User Guide
Examples
Reference
Develop
Community
4.0.0a2
Toggle main menu visibility
Loading...
Searching...
No Matches
ctexceptions.cpp
Go to the documentation of this file.
1
//! @file ctexceptions.cpp
2
3
// This file is part of Cantera. See License.txt in the top-level directory or
4
// at https://cantera.org/license.txt for license and copyright information.
5
6
#include "
cantera/base/ctexceptions.h
"
7
#include "
application.h
"
8
#include "
cantera/base/global.h
"
9
10
#define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED
11
#include <boost/stacktrace.hpp>
12
13
#include <sstream>
14
15
namespace
Cantera
16
{
17
18
int
CanteraError::traceDepth_
= 0;
19
20
CanteraError::CanteraError
(
const
string
& procedure) :
21
procedure_
(procedure)
22
{
23
if
(
traceDepth_
) {
24
auto
trace = boost::stacktrace::stacktrace(0,
traceDepth_
);
25
traceback_
= boost::stacktrace::to_string(trace);
26
}
27
}
28
29
const
char
*
CanteraError::what
()
const
throw()
30
{
31
try
{
32
formattedMessage_
=
"\n"
+ string(79,
'*'
) +
"\n"
;
33
formattedMessage_
+=
getClass
();
34
if
(
procedure_
.size()) {
35
formattedMessage_
+=
" thrown by "
+
procedure_
;
36
}
37
formattedMessage_
+=
":\n"
+
getMessage
();
38
if
(
formattedMessage_
.compare(
formattedMessage_
.size()-1, 1,
"\n"
)) {
39
formattedMessage_
.append(
"\n"
);
40
}
41
if
(
traceDepth_
) {
42
formattedMessage_
+= string(79,
'-'
) +
"\n"
+
traceback_
;
43
}
44
formattedMessage_
+= string(79,
'*'
) +
"\n"
;
45
46
}
catch
(...) {
47
// Something went terribly wrong and we couldn't even format the message.
48
}
49
return
formattedMessage_
.c_str();
50
}
51
52
string
CanteraError::getMessage
()
const
53
{
54
return
msg_
;
55
}
56
57
string
CanteraError::getMethod
()
const
58
{
59
return
procedure_
;
60
}
61
62
void
CanteraError::setStackTraceDepth
(
int
depth)
63
{
64
traceDepth_
= depth;
65
}
66
67
string
ArraySizeError::getMessage
()
const
68
{
69
return
fmt::format(
"Array size ({}) too small. Must be at least {}."
,
70
sz_, reqd_);
71
}
72
73
string
IndexError::getMessage
()
const
74
{
75
if
(m_size == 0) {
76
return
fmt::format(
"IndexError: index {} given, but array{} is empty."
,
77
m_, arrayName_.empty() ? arrayName_ :
" "
+arrayName_);
78
}
79
if
(arrayName_ ==
""
) {
80
return
fmt::format(
"IndexError: {} outside valid range of 0 to {}."
,
81
m_, m_size - 1);
82
}
83
return
fmt::format(
"IndexError: {}[{}] outside valid range of 0 to {}."
,
84
arrayName_, m_, m_size - 1);
85
}
86
87
}
// namespace Cantera
application.h
Cantera::ArraySizeError::getMessage
string getMessage() const override
Method overridden by derived classes to format the error message.
Definition
ctexceptions.cpp:67
Cantera::CanteraError::what
const char * what() const override
Get a description of the error.
Definition
ctexceptions.cpp:29
Cantera::CanteraError::traceback_
string traceback_
Stack trace to location where exception was thrown.
Definition
ctexceptions.h:129
Cantera::CanteraError::getMessage
virtual string getMessage() const
Method overridden by derived classes to format the error message.
Definition
ctexceptions.cpp:52
Cantera::CanteraError::formattedMessage_
string formattedMessage_
Formatted message returned by what().
Definition
ctexceptions.h:124
Cantera::CanteraError::traceDepth_
static int traceDepth_
Number of stack frames to show.
Definition
ctexceptions.h:130
Cantera::CanteraError::procedure_
string procedure_
The name of the procedure where the exception occurred.
Definition
ctexceptions.h:123
Cantera::CanteraError::CanteraError
CanteraError()
Protected default constructor discourages throwing errors containing no information.
Definition
ctexceptions.h:117
Cantera::CanteraError::msg_
string msg_
Message associated with the exception.
Definition
ctexceptions.h:127
Cantera::CanteraError::setStackTraceDepth
static void setStackTraceDepth(int depth)
Set the number of stack frames to include when a CanteraError is displayed.
Definition
ctexceptions.cpp:62
Cantera::CanteraError::getMethod
virtual string getMethod() const
Get the name of the method that threw the exception.
Definition
ctexceptions.cpp:57
Cantera::CanteraError::getClass
virtual string getClass() const
Method overridden by derived classes to indicate their type.
Definition
ctexceptions.h:106
Cantera::IndexError::getMessage
string getMessage() const override
Method overridden by derived classes to format the error message.
Definition
ctexceptions.cpp:73
ctexceptions.h
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
global.h
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Cantera
Namespace for the Cantera kernel.
Definition
AnyMap.cpp:595
src
base
ctexceptions.cpp
Generated by
1.17.0