Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8477071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:21:09+00:00 2026-06-10T18:21:09+00:00

The following method (in a Visual Studio 2008 ref class) contains a simple error

  • 0

The following method (in a Visual Studio 2008 ref class) contains a simple error that I thought would be caught – but instead it causes the process to abort with a “Debug Assertion Failed!” message box (msg includes the offending STL vector src line#). This occurs whether compiled in Debug or Release mode. The process in this case is Excel.exe and the method is accessed via COM interop.

Can someone tell me why this error doesn’t get trapped ?

    String^ FOO()
    {
        try {
            std::vector<int> vfoo;
            vfoo.push_back(999);
            return vfoo[1].ToString();  //!!!! error: index 1 not valid
        }
        catch(std::exception& stdE) { // not catching
            return "Unhandled STL exception";
        }
        catch(System::Exception^ E) { // not catching
            return "Unhandled .NET exception: " + E->Message;
        }
        catch(...) { // not even this is catching
            return "Unhandled exception";
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:21:11+00:00Added an answer on June 10, 2026 at 6:21 pm

    In the Debug configuration you’ll get an assert that’s enabled by the iterator debugging feature. Designed to help to find mistakes in your use of the standard C++ library. You can use the Call Stack window to trace back to the statement in your code that triggered the assert. The feature is controlled by the _HAS_ITERATOR_DEBUGGING macro, very few reasons to ever turn that off in the Debug build. Well, none.

    In the Release configuration, you’ll run into the Checked Iterators feature, part of the Secure CRT Library initiative introduced at VS2005 and controlled by the _SECURE_SCL macro. It has a hook built in to get the debugger to stop, much as the above, to show you why it bombed. But not without a debugger, if none is attached then it immediately terminates your program with SEH exception code 0xc0000417. That’s kinda where the buck stops, the DLL version of the CRT was built with _SECURE_SCL in effect and you have no option to not use that DLL when you write managed code. Building with /MT is required to completely turn it off and that’s not possible in C++/CLI.

    This tends to drive C++ programmers pretty nutty, catch (…) {} is a blessed language feature even though the odds of restoring program state are very close to zero. There is a back-door however (there’s always a back-door), the argument validation code emits the error condition through a function pointer. The default handler immediately aborts the program with no way to catch it, not even with SetUnhandledExceptionFilter(). You can replace the handler with the _set_invalid_parameter_handler() function. That needs to be done by your Main() method, something like this:

    #include "stdafx.h"
    #include <stdlib.h>
    
    using namespace System;
    
    #pragma managed(push, off)
    void no_invalid_parameter_exit(const wchar_t * expression, const wchar_t * function, 
                                   const wchar_t * file, unsigned int line, uintptr_t pReserved) {
        throw new std::invalid_argument("invalid argument");
    }
    #pragma managed(pop)
    
    int main(array<System::String ^> ^args)
    {
        _set_invalid_parameter_handler(no_invalid_parameter_exit);
        // etc...
    }
    

    Which will run one of your catch handlers. The managed one, leaving no decent breadcrumbs to show what happened, but that’s normal for native C++ exceptions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Visual Studio 2008 solution that's currently consisting of three projects: A
I'm using Visual Studio 2008. I have this class: template <bool T1> class Foo
I'm working on a visual studio 2008 add-in that will generate data-access code by
I use Visual C++ 2008 in Visual Studio 2008. I frequently use the following
The following method does not compile. Visual Studio warns An out parameter may not
Is there any Visual Studio Add-In that can do the remove method refactoring? Suppose
The following method calculates cost. It access other classes when required. Cloud class holds
The following method does its job but keeps printing a warning also, im pretty
I have the following method that returns void and I need to use it
I am using ASP.NET MVC 2 & .Net 3.5 with Visual Studio 2008. Ok,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.