// debug\exception.hpp
namespace debug {
class exception
{
public:
exception()
virtual ~exception()
virtual void output(bool log_to_file = false) const = 0;
protected:
static unsigned int instances;
};
// things you must define
extern const char error_title[];
extern const char log_file_name[];
};
// debug\exception.cpp
#include "exception.hpp"
namespace debug {
unsigned int exception::instances = 0;
exception::exception()
{
instances++;
}
exception::~exception()
{
}
};
// direct_x\exception.hpp
namespace direct_x {
// exceptions
class exception
: public debug::exception
{
public:
explicit exception(const long error_code = 0)
virtual void output(bool log_to_file = false) const;
inline const long get_error_code() const
{ return( error_code ); }
protected:
const long error_code;
};
};
// direct_x\exception.cpp
namespace direct_x {
exception::exception(const long error_code)
: error_code(error_code)
{
}
void exception::output(bool log_to_file) const
{
std::stringstream text;
text << std::endl;
text << "number: " << exception::instances << std::endl;
text << "name: " << typeid(*this).name() << std::endl;
text << "error code: " << error_code << std::endl;
std::string title(debug::error_title);
if( log_to_file == false )
{
// output to the user
MessageBox(window_handle, text.str().c_str(), title.c_str(), MB_OK);
}
else
{
// output to the log file
std::fstream log(debug::log_file_name, std::ios::app / std::ios::out);
log << title << std::endl;
log << text.str();
}
}
};
// somewhere in another file
if( FAILED( hr ) )
throw direct_x::surface_creation(hr);
|
quote:
Map.cpp c:\program files\microsoft visual studio\myprojects\battle force\editor\source\map.cpp(417) : error C2440: ''type cast'' : cannot convert from ''long'' to ''class direct_x::surface_creation'' No constructor could take the source type, or constructor overload resolution was ambiguous c:\program files\microsoft visual studio\myprojects\battle force\editor\source\map.cpp(448) : error C2440: ''type cast'' : cannot convert from ''long'' to ''class direct_x::surface_creation'' No constructor could take the source type, or constructor overload resolution was ambiguous
- null_pointer Sabre Multimedia