I'm trying to compile this source code :
// exception_set_unexpected.cpp
// compile with: /c /EHsc
#include<exception>
#include<iostream>
using namespace std;
void unfunction( )
{
cout << "I'll be back." << endl;
terminate( );
}
int main( )
{
unexpected_handler oldHand = set_unexpected( unfunction );
unexpected( );
}
How can i add compile with: /c /EHsc
option in Visual Studio 2010 ?
With a solution open in Visual Studio, use Debug > Windows > Exception Settings to open the Exception Settings window.
cl /EHsc main. cpp // "/EHsc" specifies that only standard C++ ("synchronous") exceptions will be caught, // and `extern "C"` functions will not throw exceptions. // This is recommended when writing portable, platform-independent code.
In Visual StudioIn the left pane, select Configuration Properties, C/C++ and then choose the compiler option category. The topic for each compiler option describes how it can be set and where it is found in the development environment.
An exception is a problem that arises during the execution of a program. A C++ exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.
Right click on your project -> Properties -> Configuration Properties -> C/C++ -> Command Line
Put your flags in the command Line
To set this compiler option in the Visual Studio development environment
- Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.
- Click the C/C++ folder.
- Click the Code Generation property page.
- Set Enable C++ Exceptions to Yes (/EHsc).
- Click the Command Line property page.
- Type the compiler option in the Additional Options box (/c).
More info here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With