Buffer Interface
Classes | Public Member Functions | Protected Member Functions | List of all members
BFExceptionBase Class Reference

Base class of all BitFlow exception classes. More...

#include <BFException.hpp>

Inheritance diagram for BFExceptionBase:
BFCiException BiException CLComm::BFCLException

Classes

struct  PrivateData
 

Public Member Functions

 BFExceptionBase (void)
 
 BFExceptionBase (BFExceptionBase const &to_copy)
 
 BFExceptionBase (BFExceptionBase &&to_take)
 
virtual ~BFExceptionBase (void)
 
BFExceptionBaseoperator= (BFExceptionBase const &to_copy)
 
BFExceptionBaseoperator= (BFExceptionBase &&to_take)
 
virtual BFU32 getErrorText (PBFCHAR ErrorText, PBFU32 ErrorTextSize) const
 
virtual std::string getErrorText (void) const
 
virtual BFU32 getErrorNumber (void) const
 
virtual BFU32 showErrorMsg (void) const
 

Protected Member Functions

 BFExceptionBase (const BFU32 number, std::string const &message)
 
 BFExceptionBase (const BFU32 number, std::string &&message)
 

Detailed Description

Base class of all BitFlow exception classes.

Examples:
BiSimplePlusPlus.cpp, CircClassExample.cpp, and CircHoldSimple.cpp.

Constructor & Destructor Documentation

BFExceptionBase::BFExceptionBase ( void  )

Construct the BFExceptionBase instance with no error.

37  : m_pd ( new PrivateData )
38 { }
BFExceptionBase::BFExceptionBase ( BFExceptionBase const &  to_copy)

Construct a BFExceptionBase instance, copying the number and message from the exception to_copy.

Parameters
[in]to_copy- The exception to be copied.
66  : m_pd ( new PrivateData(to_copy.m_pd->m_number, to_copy.m_pd->m_message) )
67 { }
BFExceptionBase::BFExceptionBase ( BFExceptionBase &&  to_take)

Construct a BFExceptionBase instance, taking the data from the exception to_take.

Parameters
[in]to_take- The exception to be taken.
75  : m_pd (to_take.m_pd)
76 {
77  to_take.m_pd = nullptr;
78 }
BFExceptionBase::~BFExceptionBase ( void  )
virtual

Clean up this BFExceptionBase instance and its resources.

84 {
85  delete m_pd;
86 }
BFExceptionBase::BFExceptionBase ( const BFU32  number,
std::string const &  message 
)
protected

Construct the BFExceptionBase instance with an error number and message.

Parameters
[in]number- The error code to for this BFExceptionBase.
[in]message- The error message for this BFExceptionBase.
47  : m_pd ( new PrivateData(number, message) )
48 { }
BFExceptionBase::BFExceptionBase ( const BFU32  number,
std::string &&  message 
)
protected

Construct the BFExceptionBase instance with an error number and message.

Parameters
[in]number- The error code to for this BFExceptionBase.
[in]message- The error message for this BFExceptionBase.
57  : m_pd ( new PrivateData(number, std::move(message)) )
58 { }

Member Function Documentation

BFU32 BFExceptionBase::getErrorNumber ( void  ) const
virtual

Returns the error number of the error that occured.

Referenced by showErrorMsg(), and BiException::showErrorMsg().

173 {
174  return m_pd->m_number;
175 }
BFU32 BFExceptionBase::getErrorText ( PBFCHAR  errorText,
PBFU32  errorBufferSize 
) const
virtual

Returns a string description of the error that occured.

Parameters
[out]errorText- The pointer to the users allocated buffer that will store the text error message.
[in,out]errorBufferSize- As an input, this parameter is the number of bytes that errorText buffer can hold. As an output, the paramerter is overwritten with the number of bytes written to the errorText buffer when successful or the number of bytes the buffer needs to be to hold the full message if the buffer is too small.
Returns
BI_OK if the method was successful, or on of the following on error:

References BI_ERROR_BUFFER_TOO_SMALL, BI_ERROR_NULL_TEXT_PTR, and getErrorText().

141 {
142  const std::string message = getErrorText();
143 
144  const size_t inputSize = *errorBufferSize;
145  const size_t errTxtSize = message.size() + 1;
146 
147  *errorBufferSize = BFU32(errTxtSize);
148 
149  if (!errorText)
150  return BI_ERROR_NULL_TEXT_PTR;
151 
152  if (inputSize)
153  {
154  std::memcpy(errorText, message.c_str(), std::min(inputSize, errTxtSize));
155  errorText[inputSize - 1] = 0;
156  }
157 
158  return inputSize < errTxtSize ? BI_ERROR_BUFFER_TOO_SMALL : BF_OK;
159 }
unsigned long BFU32
Definition: BFTypeNT.h:55
Definition: BiError.h:330
virtual std::string getErrorText(void) const
Definition: BFException.cpp:164
Definition: BiError.h:332
std::string BFExceptionBase::getErrorText ( void  ) const
virtual

Return the error text as a std::string. Throws a BFException on any error.

Referenced by getErrorText(), and showErrorMsg().

165 {
166  return m_pd->m_message;
167 }
BFExceptionBase & BFExceptionBase::operator= ( BFExceptionBase const &  to_copy)

Replace the data stored in this exception with copies of the data from the exception to_copy.

Parameters
[in]to_copy- The exception to be copied.
Returns
A reference to this exception.

Referenced by BFCiException::operator=(), BiException::operator=(), and CLComm::BFCLException::operator=().

96 {
97  if (this != &to_copy)
98  {
99  m_pd->m_number = to_copy.m_pd->m_number;
100  m_pd->m_message = to_copy.m_pd->m_message;
101  }
102  return *this;
103 }
BFExceptionBase & BFExceptionBase::operator= ( BFExceptionBase &&  to_take)

Replace the data stored in this exception data taken from the exception to_take.

Parameters
[in]to_take- The exception to be taken.
Returns
A reference to this exception.
113 {
114  if (this != &to_take)
115  {
116  delete m_pd;
117  m_pd = to_take.m_pd;
118  to_take.m_pd = nullptr;
119  }
120  return *this;
121 }
BFU32 BFExceptionBase::showErrorMsg ( void  ) const
virtual

Pops up a dialog displaying a text description of the error that was thrown.

Returns
Returns one of the following:
  • BI_OK - The user clicked on the ok button on the dialog.
  • BI_CANCEL - The user clicked on the cancel button on the dialog.

Reimplemented in BiException.

Examples:
BiSimplePlusPlus.cpp, CircClassExample.cpp, and CircHoldSimple.cpp.

References BI_CANCEL, BI_OK, getErrorNumber(), and getErrorText().

186 {
187  const BFU32 errorNumber = getErrorNumber();
188 
189  std::ostringstream txtStrm;
190  txtStrm << "BitFlow Error " << errorNumber << ": " << getErrorText();
191 
192  UINT mType = MB_OKCANCEL|(BF_OK == errorNumber ? MB_ICONEXCLAMATION : MB_ICONERROR);
193  const int uButton = MessageBoxA(NULL, txtStrm.str().c_str(), "Frame Grabber Error", mType);
194 
195  if (IDOK == uButton)
196  return BI_OK;
197 
198  return BI_CANCEL;
199 }
unsigned long BFU32
Definition: BFTypeNT.h:55
virtual std::string getErrorText(void) const
Definition: BFException.cpp:164
#define BI_CANCEL
Definition: BiDef.h:36
virtual BFU32 getErrorNumber(void) const
Definition: BFException.cpp:172
Definition: BiError.h:19

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