| Cantera 3.0.0

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#include <sstream>
11
12 namespace Cantera
13{
14
15// *** Exceptions ***
16
17 static const char* stars = ("*****************************************"
18 "**************************************\n");
19
20 CanteraError::CanteraError(const string& procedure) :
21 procedure_(procedure)
22{
23}
24
25 const char* CanteraError::what() const throw()
26{
27 try {
28 formattedMessage_ = "\n";
29 formattedMessage_ += stars;
30 formattedMessage_ += getClass();
31 if (procedure_.size()) {
32 formattedMessage_ += " thrown by " + procedure_;
33 }
34 formattedMessage_ += ":\n" + getMessage();
35 if (formattedMessage_.compare(formattedMessage_.size()-1, 1, "\n")) {
36 formattedMessage_.append("\n");
37 }
38 formattedMessage_ += stars;
39 } catch (...) {
40 // Something went terribly wrong and we couldn't even format the message.
41 }
42 return formattedMessage_.c_str();
43}
44
45 string CanteraError::getMessage() const
46{
47 return msg_;
48}
49
50 string CanteraError::getMethod() const
51{
52 return procedure_;
53}
54
55 string ArraySizeError::getMessage() const
56{
57 return fmt::format("Array size ({}) too small. Must be at least {}.",
58 sz_, reqd_);
59}
60
61 string IndexError::getMessage() const
62{
63 return fmt::format("IndexError: {}[{}] outside valid range of 0 to {}.",
64 arrayName_, m_, mmax_);
65}
66
67} // namespace Cantera
application.h
Cantera::ArraySizeError::getMessage
string getMessage() const override
Method overridden by derived classes to format the error message.
Definition ctexceptions.cpp:55
Cantera::CanteraError::what
const char * what() const override
Get a description of the error.
Definition ctexceptions.cpp:25
Cantera::CanteraError::getMessage
virtual string getMessage() const
Method overridden by derived classes to format the error message.
Definition ctexceptions.cpp:45
Cantera::CanteraError::formattedMessage_
string formattedMessage_
Formatted message returned by what()
Definition ctexceptions.h:120
Cantera::CanteraError::procedure_
string procedure_
The name of the procedure where the exception occurred.
Definition ctexceptions.h:119
Cantera::CanteraError::CanteraError
CanteraError()
Protected default constructor discourages throwing errors containing no information.
Definition ctexceptions.h:113
Cantera::CanteraError::msg_
string msg_
Message associated with the exception.
Definition ctexceptions.h:123
Cantera::CanteraError::getMethod
virtual string getMethod() const
Get the name of the method that threw the exception.
Definition ctexceptions.cpp:50
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:61
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:564