# How to disable C++ exception handling using macros?
Thu
28
Jul 2016
Some time ago my colleague showed me a clever way to disable exception handling in C++ using a set of preprocessor macros:
#define throw
#define try if(true)
#define catch(...) if(false)
Please note that:
throw is a macro without arguments that resolves to just nothing, so the expression following it will become a standalone expression with its result discarded.try is a macro without arguments that resolves to an "if" statement, that will smoothly merge with the following { } braces.catch is also a macro that resolves to "if" statement, but it takes variable number or arguments and doesn't use them in its definition.So following code that uses exception:
try
{
// Do something
if(somethingFailed)
throw std::exception("Message.");
}
catch(const std::exception& e)
{
// Handle the exception.
}
Will resolve after defining these three macros to following:
if(true)
{
// Do something
if(somethingFailed)
std::exception("Message.");}if(false){
// Handle the exception.
}
Of course it's not a solution to any real problem, unless you just want your try...catch blocks to stop working. Disabling exception handling for real (and associated performance penalty, as well as binary code size overhead) is the matter of compiler options. And of course this trick makes errors not handled properly, so when an exception would be thrown, the program will just continue and something bad will happen instead.
But I think the trick is interesting anyway, because it shows how powerful C++ is (it empowers you to do stupid things :)
# Upgrade to Windows 10 - My Story
Wed
20
Jul 2016
I upgraded my system to Windows 10. Free upgrade is avaiable until July 28th for all genuine users of Windows 7, 8 and 8.1, so now it's high time to do it if you don't want to pay for it later. My upgrade went well, but not without problems. Here is my story:
First some basic information:
On my old Toshiba laptop with Windows 7, bought in 2011, the upgrade failed. The system is not broken though - Windows 7 still works. After the failure I checked manufacturer's website and found that there are no drivers for this model for any operating system newer than Windows 7, so it's good to stay this way.
On my new Lenovo laptop with Windows 8.1, bought in 2015, I was able to successfully perform the upgrade suggested by the system. All the devices work correctly. All installed programs and settings are also preserved.
On my PC, with most components bought in 2013, upgrade to Windows 10 also failed. I can remember fighting with this annoying upgrade window and deleting some system files few months ago, so that might be the reason. I was ready to format my system disk and install everything from scratch anyway, so here is what I did:
I could find drivers for Windows 10 for all my components and peripherals and they all work correctly (except only an old, little webcam - ModeCom MC-1.3M, but I don't use it anyway). I could also install all the programs that I need and they seem to work.
I recommend you to also get your free upgrade to Windows 10. I had an opportunity to work with this system a lot and I could say it's not that bad :) I know there are some arguments against the new Windows version, so let's look at them:
There are some advantages of the new Windows as well, especially compared to Windows 8.x. There is no Charms Bar and Hot Corners when you but your mouse cursor in the corner of the screen. Start Menu is back with just few tiles you can configure and the old good list of installed applications. (You can always get even more old-fashioned Start Menu by installing free app: Classic Shell).
But the most important is what's not visible to the naked eye. As a developer I know that a new operating system is not about new looks of buttons and menus or new Calc application, but mostly about new technologies under the hood. Some of them (like Direct3D 12 and WDDM 2.0, to name just these related to graphics) are available in Windows 10 only. Some applications and games will require them to work sooner or later. That's the reason I believe it's worth upgrading to Windows 10 as long as it's free.
I plan to update my blog more often now, so I invite you to come back here from time to time or subscribe to my RSS channel.