Random Chitchat 2018
#37
Dear diary,
today exceptions bit me unusually hard. I am seriously considering filing a compiler bug report...

When thinking about exceptions, one would argue that any code that is after a "throw" statement will never get executed, right? Try the following code in MSVC2017 debug build:
#include <iostream>
using namespace std;

int main()
{
	cout << "Start" << endl;
	class TestException:
		std::runtime_error
	{
	public:
		TestException():
			std::runtime_error("TestException")
		{
		}
	};

	try
	{
		throw TestException();
		cout << "After throw" << endl;
	}
	catch (const std::runtime_error & exc)
	{
		cout << "Caught a runtime_error" << endl;
	}
	cout << "Done" << endl;
	return 0;
}

So, what does it do in reality? It prints "Start", "After throw", and "Done", and exits with code 0. WTF?!? How can the "After throw" line be printed??

Let's try release build, then. That one depends whether you run it in the MSVC debugger, or standalone. In the debugger, it prints "Start", "After throw" and jumps into nonexistent memory. WTF again? Standalone, it finally behaves as one would expect: prints "Start" and crashes.

I've spent a good hour hunting this bug. Turns out, the only thing I forgot in the code above is the "public" inheritance keyword in TestException's declaration. But still, without it the code behaves just weird.
Thanks given by:


Messages In This Thread
Random Chitchat 2018 - by xoft - 01-02-2018, 03:15 PM
RE: Random Chitchat 2018 - by ShadowCone - 01-02-2018, 05:01 PM
RE: Random Chitchat 2018 - by xoft - 01-14-2018, 09:21 AM
RE: Random Chitchat 2018 - by ShadowCone - 01-14-2018, 09:00 PM
RE: Random Chitchat 2018 - by xoft - 01-15-2018, 01:26 PM
RE: Random Chitchat 2018 - by ShadowCone - 01-16-2018, 06:41 AM
RE: Random Chitchat 2018 - by xoft - 01-16-2018, 05:57 PM
RE: Random Chitchat 2018 - by Mathias - 01-28-2018, 12:59 AM
RE: Random Chitchat 2018 - by peterbell10 - 01-28-2018, 08:50 AM
RE: Random Chitchat 2018 - by tonibm19 - 03-12-2018, 11:33 PM
RE: Random Chitchat 2018 - by xoft - 03-15-2018, 06:06 PM
RE: Random Chitchat 2018 - by xoft - 05-01-2018, 07:01 AM
RE: Random Chitchat 2018 - by Mathias - 05-16-2018, 07:33 AM
RE: Random Chitchat 2018 - by xoft - 05-01-2018, 07:58 AM
RE: Random Chitchat 2018 - by yangm97 - 06-19-2018, 05:03 PM
RE: Random Chitchat 2018 - by ShadowCone - 06-20-2018, 08:12 AM
RE: Random Chitchat 2018 - by Morrissey - 07-11-2018, 09:40 PM
RE: Random Chitchat 2018 - by tigerw - 07-16-2018, 06:45 AM
RE: Random Chitchat 2018 - by tigerw - 07-16-2018, 06:51 AM
RE: Random Chitchat 2018 - by peterbell10 - 07-20-2018, 07:52 AM
RE: Random Chitchat 2018 - by xoft - 07-20-2018, 05:41 PM
RE: Random Chitchat 2018 - by NiLSPACE - 07-20-2018, 10:07 PM
RE: Random Chitchat 2018 - by tigerw - 07-25-2018, 04:39 AM
RE: Random Chitchat 2018 - by NiLSPACE - 07-25-2018, 07:41 PM
RE: Random Chitchat 2018 - by xoft - 07-25-2018, 08:15 PM
RE: Random Chitchat 2018 - by tigerw - 07-26-2018, 12:43 AM
RE: Random Chitchat 2018 - by tigerw - 07-26-2018, 12:42 AM
RE: Random Chitchat 2018 - by xoft - 07-27-2018, 05:40 AM
RE: Random Chitchat 2018 - by tigerw - 07-27-2018, 10:35 PM
RE: Random Chitchat 2018 - by Mathias - 08-07-2018, 09:02 AM
RE: Random Chitchat 2018 - by xoft - 08-31-2018, 02:41 PM
RE: Random Chitchat 2018 - by NiLSPACE - 08-31-2018, 05:06 PM
RE: Random Chitchat 2018 - by ShadowCone - 09-01-2018, 06:29 AM
RE: Random Chitchat 2018 - by ThuGie - 09-01-2018, 10:16 AM
RE: Random Chitchat 2018 - by xoft - 09-03-2018, 07:41 AM
RE: Random Chitchat 2018 - by tonibm19 - 09-06-2018, 02:49 AM
RE: Random Chitchat 2018 - by xoft - 10-22-2018, 10:20 PM
RE: Random Chitchat 2018 - by NiLSPACE - 10-23-2018, 12:24 AM
RE: Random Chitchat 2018 - by tonibm19 - 12-25-2018, 09:14 PM
RE: Random Chitchat 2018 - by tigerw - 12-26-2018, 02:12 AM
RE: Random Chitchat 2018 - by ThuGie - 12-26-2018, 10:13 PM
RE: Random Chitchat 2018 - by xoft - 12-27-2018, 01:55 AM
RE: Random Chitchat 2018 - by xoft - 12-27-2018, 02:07 AM
RE: Random Chitchat 2018 - by NiLSPACE - 12-27-2018, 06:09 AM
RE: Random Chitchat 2018 - by ShadowCone - 12-28-2018, 05:25 PM
RE: Random Chitchat 2018 - by ThuGie - 12-29-2018, 09:57 AM
RE: Random Chitchat 2018 - by Mathias - 01-02-2019, 06:25 PM



Users browsing this thread: 13 Guest(s)