Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable C++ exceptions in Visual Studio 2010 compilation options

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 ?

like image 954
penguru Avatar asked Jul 21 '10 12:07

penguru


People also ask

How to check inner exception in Visual Studio?

With a solution open in Visual Studio, use Debug > Windows > Exception Settings to open the Exception Settings window.

What is cl EHsc?

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.

How do I add a compiler flag in Visual Studio?

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.

What is c++ EH exception?

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.


2 Answers

Right click on your project -> Properties -> Configuration Properties -> C/C++ -> Command Line

Put your flags in the command Line

like image 100
DumbCoder Avatar answered Sep 19 '22 05:09

DumbCoder


To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see How to: Open Project Property Pages.
  2. Click the C/C++ folder.
  3. Click the Code Generation property page.
  4. Set Enable C++ Exceptions to Yes (/EHsc).
  5. Click the Command Line property page.
  6. Type the compiler option in the Additional Options box (/c).

More info here.

like image 33
Kirill V. Lyadvinsky Avatar answered Sep 23 '22 05:09

Kirill V. Lyadvinsky