/**
 * \file BGDNetException.cpp
 * \brief Реализация класса Exception
 */

#include "BGDNetPch.h"

#include "BGDNetException.h"

#include <stdio.h>

#ifdef BGDNET_USE_MFC
# ifdef _DEBUG
#   define new DEBUG_NEW
#   undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
# endif
#endif

namespace BGDNet
{

Exception::Exception( NWCCODE errCode, const char* errMsg ) :
  m_errCode(errCode)
{
  char buf[64];
  sprintf(buf, "0x%04X", errCode);
  if (!errMsg)
    m_pMsg = new string(buf);
  else
  {
    m_pMsg = new string(errMsg);
    m_pMsg ->append(" (");
    m_pMsg->append(buf);
    m_pMsg->append(")");
  }
}

Exception::Exception( const Exception& e )
{
  m_pMsg = new string(*e.m_pMsg);
}

Exception::~Exception( void )
{
  if (m_pMsg)
    delete m_pMsg;
}

Exception& Exception::operator =( const Exception& e )
{
  if (this != &e)
  {
    delete m_pMsg;
    m_pMsg = new string(*e.m_pMsg);
  }
  return *this;
}

NWCCODE Exception::code( void ) const
{
  return m_errCode;
}

const char* Exception::what( void ) const
{
  return m_pMsg->c_str();
}

} // namespace BGDNet
