Structured Exception Handling in Visual C++

  • The /EHa compiler option supports handling of both standard C++ exceptions (software exceptions) and hardware exceptions by using the C++ try and catch clause. To implement SEH without specifying /EHa, you may use the __try, __except, and __finally syntax.
  • Specifying /EHa and trying to handle all exceptions by using catch(…) can be dangerous. In most cases, asynchronous exceptions are unrecoverable and should be considered fatal. Catching them and proceeding can cause process corruption and lead to bugs that are hard to find and fix.
  • When you use /EHsc or /EHs, the compiler assumes that exceptions can only occur at a throw statement or at a function call. This assumption allows the compiler to eliminate code for tracking the lifetime of many unwindable objects, which can significantly reduce code size. If you use /EHa, your executable image may be larger and slower, because the compiler doesn’t optimize try blocks as aggressively. It also leaves in exception filters that automatically clean up local objects, even if the compiler doesn’t see any code that can throw a C++ exception.
  • Structured Exception Handling (SEH) is a Microsoft extension to C to handle certain exceptional code situations, such as hardware faults, gracefully. Although Windows and Microsoft Visual C++ support SEH, we strongly recommend that you use ISO-standard C++ exception handling (with /EHsc or /EHs). It makes your code more portable and flexible.




C++ Programmer at Microsoft

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Making our Game more Immersive using Sound

A Brief Introduction to FastAPI

My journey through grokking a contribution that is coded in a language that I have never coded in

Spring Cache Abstraction with Couchbase

Packages in Go

Dev of the day, or not, that is the question

What I Learned at Work this Week: AWS Transfer Family

Galaxy Shooter — Player Movement

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amit Kumar Parida

Amit Kumar Parida

C++ Programmer at Microsoft

More from Medium

Scoped lock c++

5 Unpopular yet useful git commands

C++ fluent builder pattern

Building an API in C++ With Pistache