LSSTApplications  11.0-24-g0a022a1,14.0+77,15.0,15.0+1
LSSTDataManagementBasePackage
Public Member Functions | List of all members
lsst::pex::exceptions::MemoryError Class Reference

#include <Runtime.h>

Inheritance diagram for lsst::pex::exceptions::MemoryError:
lsst::pex::exceptions::RuntimeError lsst::pex::exceptions::Exception std::exception

Public Member Functions

void addMessage (char const *file, int line, char const *func, std::string const &message)
 Add a tracepoint and a message to an exception before rethrowing it (access via LSST_EXCEPT_ADD). More...
 
Traceback const & getTraceback (void) const throw ()
 Retrieve the list of tracepoints associated with an exception. More...
 
virtual std::ostreamaddToStream (std::ostream &stream) const
 Add a text representation of this exception, including its traceback with messages, to a stream. More...
 
virtual char const * what (void) const throw ()
 Return a character string summarizing this exception. More...
 
what (T... args)
 
virtual char const * getType (void) const throw ()
 Return the fully-specified C++ type of a pointer to the exception. More...
 
virtual Exceptionclone (void) const
 Return a copy of the exception as an Exception*. More...
 

Detailed Description

Definition at line 46 of file Runtime.h.

Member Function Documentation

◆ addMessage()

void Exception::addMessage ( char const *  file,
int  line,
char const *  func,
std::string const &  message 
)
inherited

Add a tracepoint and a message to an exception before rethrowing it (access via LSST_EXCEPT_ADD).

Parameters
[in]fileFilename (automatically passed in by macro).
[in]lineLine number (automatically passed in by macro).
[in]funcFunction name (automatically passed in by macro).
[in]messageAdditional message to associate with this rethrow.

Definition at line 55 of file Exception.cc.

57  {
59  stream << _message;
60  if (_traceback.empty()) {
61  // This means the message-only constructor was used, which should only happen
62  // from Python...but this method isn't accessible from Python, so maybe
63  // this Exception was thrown in Python, then passed back to C++. Or, more
64  // likely, someone didn't read the warning and threw this exception in C++
65  // without using LSST_EXCEPT.
66  // But, because we don't have a traceback for that first message, we can't
67  // add one here without messing up the stringification logic later. Since
68  // this is a rare case (and should be considered a bug, but we don't want
69  // exception code throwing its own exceptions unless it absolutely has to),
70  // we'll proceed by just appending the message and ignoring the traceback.
71  stream << "; " << message;
72  } else {
73  if (_traceback.size() == static_cast<std::size_t>(1)) {
74  // The original message doesn't have an index (because it's faster,
75  // and there's no need if there's only one), so when we add the second,
76  // we have to give it an index.
77  stream << " {0}; ";
78  } else {
79  stream << "; ";
80  }
81  stream << message << " {" << _traceback.size() << "}";
82  _traceback.push_back(Tracepoint(file, line, func, message));
83  }
84  _message = stream.str();
85 
86 }
T empty(T... args)
T push_back(T... args)
T str(T... args)
def line(points, frame=None, origin=afwImage.PARENT, symbs=False, ctype=None, size=0.5)
Definition: ds9.py:113
T size(T... args)

◆ addToStream()

std::ostream & Exception::addToStream ( std::ostream stream) const
virtualinherited

Add a text representation of this exception, including its traceback with messages, to a stream.

Parameters
[in]streamReference to an output stream.
Returns
Reference to the output stream after adding the text.

Definition at line 93 of file Exception.cc.

93  {
94  if (_traceback.empty()) {
95  // The exception was raised in Python, so we don't include the traceback, the type, or any
96  // newlines, because Python will print those itself.
97  stream << _message;
98  } else {
99  stream << std::endl; // Start with a newline to separate our stuff from Pythons "<type>: " prefix.
100  for (std::size_t i = 0; i != _traceback.size(); ++i) {
101  stream << " File \"" << _traceback[i]._file
102  << "\", line " << _traceback[i]._line
103  << ", in " << _traceback[i]._func << std::endl;
104  stream << " " << _traceback[i]._message << " {" << i << "}" << std::endl;
105  }
106  std::string type(getType(), 0, std::strlen(getType()) - 2);
107  stream << type << ": '" << _message << "'" << std::endl;
108  }
109  return stream;
110 }
virtual char const * getType(void) const
Return the fully-specified C++ type of a pointer to the exception.
Definition: Exception.cc:116
T empty(T... args)
T endl(T... args)
STL class.
T strlen(T... args)
T size(T... args)

◆ clone()

Exception * Exception::clone ( void  ) const
virtualinherited

Return a copy of the exception as an Exception*.

Can be overridden by derived classes that add data or methods.

Returns
Exception* pointing to a copy of the exception.

Reimplemented in lsst::pex::policy::UnsupportedSyntax, lsst::pex::policy::FormatSyntaxError, lsst::pex::policy::SyntaxError, lsst::pex::policy::EOFError, lsst::pex::policy::TypeError, lsst::pex::policy::NameNotFound, lsst::pex::policy::ParserError, lsst::pex::policy::DictionaryError, lsst::meas::base::MeasurementError, and lsst::pex::policy::BadNameError.

Definition at line 120 of file Exception.cc.

120  {
121  return new Exception(*this);
122 }
Exception(char const *file, int line, char const *func, std::string const &message)
Standard constructor, intended for C++ use via the LSST_EXCEPT() macro.
Definition: Exception.cc:44

◆ getTraceback()

Traceback const & Exception::getTraceback ( void  ) const
throw (
)
inherited

Retrieve the list of tracepoints associated with an exception.

Definition at line 89 of file Exception.cc.

89  {
90  return _traceback;
91 }

◆ getType()

char const * Exception::getType ( void  ) const
throw (
)
virtualinherited

Return the fully-specified C++ type of a pointer to the exception.

This is overridden by derived classes (automatically if the LSST_EXCEPTION_TYPE macro is used). It is used by the Python interface.

Returns
String with the C++ type; does not need to be freed/deleted.

Reimplemented in lsst::pex::policy::UnsupportedSyntax, lsst::pex::policy::FormatSyntaxError, lsst::pex::policy::SyntaxError, lsst::pex::policy::EOFError, lsst::pex::policy::TypeError, lsst::pex::policy::NameNotFound, lsst::pex::policy::ParserError, lsst::pex::policy::DictionaryError, lsst::meas::base::MeasurementError, and lsst::pex::policy::BadNameError.

Definition at line 116 of file Exception.cc.

116  {
117  return "lsst::pex::exceptions::Exception *";
118 }

◆ what()

char const * Exception::what ( void  ) const
throw (
)
virtualinherited

Return a character string summarizing this exception.

This combines all the messages added to the exception, but not the type or traceback (use the stream operator to get this more detailed information).

Not allowed to throw any exceptions.

Returns
String representation; does not need to be freed/deleted.
Examples:
statistics.cc.

Definition at line 112 of file Exception.cc.

112  {
113  return _message.c_str();
114 }
T c_str(T... args)

The documentation for this class was generated from the following file: