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 6846679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:39:11+00:00 2026-05-27T00:39:11+00:00

I run the following function to load a file. It is being ported from

  • 0

I run the following function to load a file. It is being ported from CLI to standard C++ and exhibits unexpected behaviour when I attempt to specify that I would like to throw all exceptions except EOF.

bool parseFile(ManagedClass *%parsedFileAsManagedObject, const string &fileName);
    std::string line;
    bool success = true;
    ifstream is(fileName.c_str());
    //Unless I comment out the following line I get problems
    is.exceptions( ifstream::badbit | ifstream::failbit );
    //do stuff
    try {
        while (getline(is, line)) {
        //do stuff again
            parsedFileAsManagedObject = gcnew ManagedClass(12, 44);
        }
    } catch (Exception ^ex) {
        log(ex->ToString() + ex->StackTrace + ex->InnerException);
        success = false;
        //Hit debugger here.
    }
    return success;
}

When run as above I get:

External component has thrown an exception.

at _CxxThrowException(Void* , _s__ThrowInfo* )

at std.ios_base.clear(ios_base* , Int32 _State, Boolean _Reraise) in c:\program files\microsoft visual studio 9.0\vc\include\xiosbase:line 294

at std.basic_ios<char,std::char_traits<char> >.clear(basic_ios<char\,std::char_traits<char> >* , Int32 _State, Boolean _Reraise) in c:\program files\microsoft visual studio 9.0\vc\include\ios:line 44

at std.basic_ios<char,std::char_traits<char> >.setstate(basic_ios<char\,std::char_traits<char> >* , Int32 _State, Boolean _Reraise) in c:\program files\microsoft visual studio 9.0\vc\include\ios:line 55

at std.basic_istream<char,std::char_traits<char> >._Ipfx(basic_istream<char\,std::char_traits<char> >* , Boolean _Noskip) in c:\program files\microsoft visual studio 9.0\vc\include\istream:line 120

at std.basic_istream<char,std::char_traits<char> >.sentry.{ctor}(sentry* , basic_istream<char\,std::char_traits<char> >* _Istr, Boolean _Noskip) in c:\program files\microsoft visual studio 9.0\vc\include\istream:line 76

at std.getline<char,struct std::char_traits<char>,class std::allocator<char> >(basic_istream<char\,std::char_traits<char> >* _Istr, basic_string<char\,std::char_traits<char>\,std::allocator<char> >* _Str, SByte _Delim) in c:\program files\microsoft visual studio 9.0\vc\include\string:line 483

at std.getline<char,struct std::char_traits<char>,class std::allocator<char> >(basic_istream<char\,std::char_traits<char> >* _Istr, basic_string<char\,std::char_traits<char>\,std::allocator<char> >* _Str) in c:\program files\microsoft visual studio 9.0\vc\include\string:line 531

at myprojrepeated.LevelParser.parseFile(ManagedClass *%parsedFileAsManagedObject, basic_string<char\,std::char_traits<char>\,std::allocator<char> >* fileName) in c:\documents and settings\KingKewlio\my documents\visual studio 2008\projects\myproj\myprojrepeated\levelparser.cpp:line 355

describing my exception.

When I comment out that line all is well in the land of Interop.

Can anybody explain why Interop doesn’t like it?

I attribute Interop because when I don’t bother to surround that getline(...) in try and catch I get the following error

System.Runtime.InteropServices.SEHException

reported from the top of the call stack shown above and again below:

[Managed to Native Transition]

myproj.exe!std::ios_base::clear(int _State = 3, bool _Reraise = false) Line 294 + 0x3a bytes C++

myproj.exe!std::basic_ios<char,std::char_traits<char> >::clear(int _State = 3, bool _Reraise = false) Line 45 C++

myproj.exe!std::basic_ios<char,std::char_traits<char> >::setstate(int _State = 2, bool _Reraise = false) Line 56 C++

myproj.exe!std::basic_istream<char,std::char_traits<char> >::_Ipfx(bool _Noskip = true) Line 121 C++

myproj.exe!std::basic_istream<char,std::char_traits<char> >::sentry::sentry(std::basic_istream<char,std::char_traits<char> >& _Istr = {...}, bool _Noskip = true) Line 76 + 0x18 bytes C++

myproj.exe!std::getline<char,std::char_traits<char>,std::allocator<char> >(std::basic_istream<char,std::char_traits<char> >& _Istr = {...}, std::basic_string<char,std::char_traits<char>,std::allocator<char> >& _Str = {...}, char _Delim = 10 ' ') Line 483 + 0xe bytes C++

myproj.exe!std::getline<char,std::char_traits<char>,std::allocator<char> >(std::basic_istream<char,std::char_traits<char> >& _Istr = {...}, std::basic_string<char,std::char_traits<char>,std::allocator<char> >& _Str = {...}) Line 531 + 0x33 bytes C++

An answer https://stackoverflow.com/q/8144268/866333 to my previous question indicates that this is unexpected behaviour but I am prepared to be proved wrong.

  • 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-05-27T00:39:12+00:00Added an answer on May 27, 2026 at 12:39 am

    It would appear as if std::ios_base is throwing an exception. Since it is part of the C++ standard library, the exception is probably a std::exception &. Not a Exception ^. Since your code doesn’t catch std::exception &, it is probably about to terminate. This can be confirmed by adding a

    catch (...) {
        log("Unknown exception thrown!");
        throw;  //rethrow it.  ALWAYS RETHROW UNKNOWN EXCEPTIONS.  PERIOD.
    }
    

    Also, getline(is, line) will set both EOF and failbit both, if the file ends in an empty line.

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

Sidebar

Related Questions

I have written the following function but it's isn't returning anything when I run
Can not run following SQL from ant's sql task : BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table =>
I run the following Gert's extract command to the data dump file which format
I have run the following through JSLint: $(document).ready(function() { /* Add paragraph on page
I'm using PHPs create_function($args, $code) function to dynamically load a function definition from a
how to use the perspectiveTransform function? when run my code, Will produce the following
I run the following command in Emacs unsuccessfully C-u How can you clear the
I run the following codes separately as my prompt unsuccessfully in .zshrc. This suggests
I run the following html snippet in IE8 and IE7 with non-English characters (we
When I run the following, PowerShell hangs waiting for the dialog to close, even

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.