Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualRyan_001

Posted 04 April 2013 - 02:37 PM

The problem with posting the code is that when I try to bring code from other files into the main file (so I can post it all in one spot), identical copy-pasted code will cause it to go from not working, to working.  For example, here's the main part I was able to trim it down to (this does not work):

 

struct TestException : public Exception {};		// class Exception : virtual public boost::exception, virtual public std::exception

std::string GetLineNumber (const boost::exception& e) {
	std::stringstream ss;
	//ss << 15;
	return ss.str();
	}

// ----- WinMain -----
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {

	bool show_exception = false;
	std::string error_msg = "No error has occured.";

	try {
		throw_detailed(TestException());
		}
	catch (const Exception& e) {
		show_exception = true;
		//error_msg = e.GetWindowsErrorMessage();
		error_msg = e.GetLineNumber();
		//error_msg = GetLineNumber(e);
		}
	
	return 0;
	}

 

Now if I uncomment the line "ss << 15;" it will compile and run fine.  Notice how the function is never called.  I was trying to include throw_detailed which consists of:

// ----- special includes -----
#include <boost\exception\detail\attribute_noreturn.hpp>


// ----- ExceptionCore -----
namespace ExceptionCore {

	typedef boost::error_info<struct tagTypeInfo,std::string> TypeMsgInfo;

	template <typename T> BOOST_ATTRIBUTE_NORETURN void ThrowException (T& e, const char* func, const char* file, int line) {
		e << TypeMsgInfo(typeid(T).name());
		e << ::boost::throw_function(func);
		e << ::boost::throw_file(file);
		e << ::boost::throw_line(line);
		throw e;
		}
	}


// ----- throw macro ----
//#define throw_detailed(x) BOOST_THROW_EXCEPTION(x)
#define throw_detailed(x) ::ExceptionCore::ThrowException(x,BOOST_CURRENT_FUNCTION,__FILE__,__LINE__)

 

into main.  But as soon as I copy and paste it in main, it works.  Basically anytime I change any of the code, related or not, it seems to change between working/not working, and I can find no pattern.  I've traced every intermediate value and with the VS2012 debugger they all are correct values at each step along the way.


#1Ryan_001

Posted 04 April 2013 - 02:18 PM

The problem with posting the code is that when I try to bring code from other files into the main file (so I can post it all in one spot), identical copy-pasted code will cause it to go from not working, to working.  For example, here's the main part I was able to trim it down to (this does not work):

 

struct TestException : public Exception {};		// class Exception : virtual public boost::exception, virtual public std::exception

std::string GetLineNumber (const boost::exception& e) {
	std::stringstream ss;
	//ss << 15;
	return ss.str();
	}

// ----- WinMain -----
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {

	bool show_exception = false;
	std::string error_msg = "No error has occured.";

	try {
		//MessageLoop();
		throw_detailed(TestException());
		}
	catch (const Exception& e) {
		show_exception = true;
		//error_msg = e.GetWindowsErrorMessage();
		error_msg = e.GetLineNumber();
		//error_msg = GetLineNumber(e);
		}
	catch (const std::exception& e) {
		show_exception = true;
		error_msg = e.what();
		}
	catch (...) {
		show_exception = true;
		error_msg = "Unknown exception.";
		}
	
	return 0;
	}

 

Now if I uncomment the line "ss << 15;" it will compile and run fine.  Notice how the function is never called.  I was trying to include throw_detailed which consists of:

// ----- special includes -----
#include <boost\exception\detail\attribute_noreturn.hpp>


// ----- ExceptionCore -----
namespace ExceptionCore {

	typedef boost::error_info<struct tagTypeInfo,std::string> TypeMsgInfo;

	template <typename T> BOOST_ATTRIBUTE_NORETURN void ThrowException (T& e, const char* func, const char* file, int line) {
		e << TypeMsgInfo(typeid(T).name());
		e << ::boost::throw_function(func);
		e << ::boost::throw_file(file);
		e << ::boost::throw_line(line);
		throw e;
		}
	}


// ----- throw macro ----
//#define throw_detailed(x) BOOST_THROW_EXCEPTION(x)
#define throw_detailed(x) ::ExceptionCore::ThrowException(x,BOOST_CURRENT_FUNCTION,__FILE__,__LINE__)

 

into main.  But as soon as I copy and paste it in main, it works.  Basically anytime I change any of the code, related or not, it seems to change between working/not working, and I can find no pattern.  I've traced every intermediate value and with the VS2012 debugger they all are correct values at each step along the way.


PARTNERS