Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #7811 > unrolled thread

Re: exception problem with cygwin - terminate called recursively

Started bypeter koch <peter.koch.larsen@gmail.com>
First post2011-07-14 09:00 -0700
Last post2011-07-17 11:18 +0200
Articles 12 — 4 participants

Back to article view | Back to comp.lang.c++


Contents

  Re: exception problem with cygwin - terminate called recursively peter koch <peter.koch.larsen@gmail.com> - 2011-07-14 09:00 -0700
    Re: exception problem with cygwin - terminate called recursively Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-07-14 18:11 +0200
    Re: exception problem with cygwin - terminate called recursively Ian Collins <ian-news@hotmail.com> - 2011-07-15 07:36 +1200
    Re: exception problem with cygwin - terminate called recursively Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-07-16 15:56 +0200
      Re: exception problem with cygwin - terminate called recursively Paavo Helde <myfirstname@osa.pri.ee> - 2011-07-16 11:04 -0500
        Re: exception problem with cygwin - terminate called recursively Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-07-16 19:54 +0200
          Re: exception problem with cygwin - terminate called recursively Paavo Helde <myfirstname@osa.pri.ee> - 2011-07-16 15:26 -0500
            Re: exception problem with cygwin - terminate called recursively Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-07-16 23:59 +0200
              Re: exception problem with cygwin - terminate called recursively Paavo Helde <myfirstname@osa.pri.ee> - 2011-07-16 17:39 -0500
                Re: exception problem with cygwin - terminate called recursively Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-07-17 01:17 +0200
                  Re: exception problem with cygwin - terminate called recursively Paavo Helde <myfirstname@osa.pri.ee> - 2011-07-17 02:30 -0500
                    Re: exception problem with cygwin - terminate called recursively Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-07-17 11:18 +0200

#7811 — Re: exception problem with cygwin - terminate called recursively

Frompeter koch <peter.koch.larsen@gmail.com>
Date2011-07-14 09:00 -0700
SubjectRe: exception problem with cygwin - terminate called recursively
Message-ID<27226563-9435-441f-a626-08e3ae85f811@glegroupsg2000goo.googlegroups.com>
Den torsdag den 14. juli 2011 17.48.24 UTC+2 skrev Philipp Kraus:
> On 2011-07-14 17:11:25 +0200, peter koch said:
> 
> > It seems to me that your exception either has no corresponding catch 
> > clause or that it is thrown when another exception is active: this 
> > causes std::terminate to be called.
> 
> on the main program the exception should be catched like:
> 
> myclass {
>    mymethod() {
>        if something
>              mymethod()
> 
>        throw exception
>   }
> }
> 
> main() {
>    myclass x;
>    try {
>        x.mymethod()
>   } catch (...) {}
> 
> }
> 

So you tried that program and it had the same behaviour?

> In my optinion I think if I throw an exception the complete runing 
> process would be breaked down and the exception is send to the main 
> program, if there is a try-catch the exception is be handled, if not 
> the program terminates. I don't use any threads. I don't understand why 
> Windows should be handle the exception in another way than Linux and 
> OSX !?

It does not.

> 
> Thanks for your answer
> 

If there is not a corresponding catch, std::terminate will be called. You said that std::terminate was called recursively?

Your problem might also be in the compiler flags used for the compiler.

/Peter

[toc] | [next] | [standalone]


#7812

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2011-07-14 18:11 +0200
Message-ID<ivn4fq$iog$1@online.de>
In reply to#7811
On 2011-07-14 18:00:47 +0200, peter koch said:

> Den torsdag den 14. juli 2011 17.48.24 UTC+2 skrev Philipp Kraus:
>> On 2011-07-14 17:11:25 +0200, peter koch said:
>> 
>>> It seems to me that your exception either has no corresponding catch
>>> clause or that it is thrown when another exception is active: this
>>> causes std::terminate to be called.
>> 
>> on the main program the exception should be catched like:
>> 
>> myclass {
>> mymethod() {
>> if something
>> mymethod()
>> 
>> throw exception
>> }
>> }
>> 
>> main() {
>> myclass x;
>> try {
>> x.mymethod()
>> } catch (...) {}
>> 
>> }
>> 
> 
> So you tried that program and it had the same behaviour?

yes

> 
>> In my optinion I think if I throw an exception the complete runing
>> process would be breaked down and the exception is send to the main
>> program, if there is a try-catch the exception is be handled, if not
>> the program terminates. I don't use any threads. I don't understand why
>> Windows should be handle the exception in another way than Linux and
>> OSX !?
> 
> It does not.
> 
>> 
>> Thanks for your answer
>> 
> 
> If there is not a corresponding catch, std::terminate will be called. 
> You said that std::terminate was called recursively?

Sorry, my mistake. The exception that is thrown shoudl be called recursively.

> Your problem might also be in the compiler flags used for the compiler.

I use on all systems the gcc, but I don't know any flags that are set 
for exception handling
I'm a little bit confused

Thanks

Phil

[toc] | [prev] | [next] | [standalone]


#7820

FromIan Collins <ian-news@hotmail.com>
Date2011-07-15 07:36 +1200
Message-ID<988usgF78bU6@mid.individual.net>
In reply to#7811
On 07/15/11 04:00 AM, peter koch wrote:
>
> If there is not a corresponding catch, std::terminate will be called. You said that std::terminate was called recursively?
>
> Your problem might also be in the compiler flags used for the compiler.

Please don't use the sociopathic "new" google interface, it ruins
threading!

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#7875

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2011-07-16 15:56 +0200
Message-ID<ivs5ac$c5s$1@online.de>
In reply to#7811
On 2011-07-14 18:00:47 +0200, peter koch said:

> Your problem might also be in the compiler flags used for the compiler.

Do you mean -fexceptions for the g++ command?

I'm a little bit closer on the problem context, I have mixed C and C++ 
code in the class that throws the exception. I have tested the code 
with std exceptions and try to catch it with
catch (...), catch (myexception& e) or catch(std::runtime_error e), but 
I cant catch the thrown exception. Is there any information about 
exception handling with mixed code?
I have found some articles that there are problems with mixed code and 
exception handling, but I haven't found a working solution for the 
problem. I try to recompile my sources with the -fexceptions flag, but 
that does not wort. Shoud I compile my C libraries with the flag?

Thanks a lot

Phil

[toc] | [prev] | [next] | [standalone]


#7876

FromPaavo Helde <myfirstname@osa.pri.ee>
Date2011-07-16 11:04 -0500
Message-ID<Xns9F24C20FD35B8myfirstnameosapriee@216.196.109.131>
In reply to#7875
Philipp Kraus <philipp.kraus@flashpixx.de> wrote in news:ivs5ac$c5s$1
@online.de:

> I'm a little bit closer on the problem context, I have mixed C and C++ 
> code in the class that throws the exception.
[...]
> problem. I try to recompile my sources with the -fexceptions flag, but 
> that does not wort. Shoud I compile my C libraries with the flag?

The -fexceptions flag should not have any effect on C++ code whatsoever. 
You need this for compiling any C code which is supposed to let C++ 
exceptions propagate through it. On Windows platform MSVC implements 
exceptions at the OS level so there is no such special flag needed for C 
code, but things may be different with cygwin or gcc. 

Cheers
Paavo

[toc] | [prev] | [next] | [standalone]


#7882

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2011-07-16 19:54 +0200
Message-ID<ivsj85$njn$1@online.de>
In reply to#7876
On 2011-07-16 18:04:37 +0200, Paavo Helde said:

> Philipp Kraus <philipp.kraus@flashpixx.de> wrote in news:ivs5ac$c5s$1
> @online.de:
> 
>> I'm a little bit closer on the problem context, I have mixed C and C++
>> code in the class that throws the exception.
> [...]
>> problem. I try to recompile my sources with the -fexceptions flag, but
>> that does not wort. Shoud I compile my C libraries with the flag?
> 
> The -fexceptions flag should not have any effect on C++ code whatsoever.
> You need this for compiling any C code which is supposed to let C++
> exceptions propagate through it. On Windows platform MSVC implements
> exceptions at the OS level so there is no such special flag needed for C
> code, but things may be different with cygwin or gcc.

I think this question is off-topic, but do you know a working solution for g++?
I have compiled all my libraries and my code with g++ / gcc, so should 
I set the
-fexceptions flag on each library or only on my code?

Thanks

Phil

[toc] | [prev] | [next] | [standalone]


#7885

FromPaavo Helde <myfirstname@osa.pri.ee>
Date2011-07-16 15:26 -0500
Message-ID<Xns9F24EE788D51Bmyfirstnameosapriee@216.196.109.131>
In reply to#7882
Philipp Kraus <philipp.kraus@flashpixx.de> wrote in
news:ivsj85$njn$1@online.de: 

> On 2011-07-16 18:04:37 +0200, Paavo Helde said:
> 
>> Philipp Kraus <philipp.kraus@flashpixx.de> wrote in news:ivs5ac$c5s$1
>> @online.de:
>> 
>>> I'm a little bit closer on the problem context, I have mixed C and
>>> C++ code in the class that throws the exception.
>> [...]
>>> problem. I try to recompile my sources with the -fexceptions flag,
>>> but that does not wort. Shoud I compile my C libraries with the
>>> flag? 
>> 
>> The -fexceptions flag should not have any effect on C++ code
>> whatsoever. You need this for compiling any C code which is supposed
>> to let C++ exceptions propagate through it. On Windows platform MSVC
>> implements exceptions at the OS level so there is no such special
>> flag needed for C code, but things may be different with cygwin or
>> gcc. 
> 
> I think this question is off-topic, but do you know a working solution
> for g++? I have compiled all my libraries and my code with g++ / gcc,
> so should I set the
> -fexceptions flag on each library or only on my code?

I don't know if this is off-topic or not, there is too less information. 
For example it is not clear what you mean exactly by "mix of C and C++ in 
the class" and if "your code" is C or C++. Maybe you could post a minimal 
example demonstrating the problem?

All I know that with Linux and gcc, all C code which has to be able to 
propagate exceptions through it must be compiled with -fexceptions. 
Typically such need happens when there is a callback function written in 
C++ which is called from inside some C library, and which wants to report 
an error to some higher level by throwing an exception. Note that this is 
still a bad idea as C does not have automatic destructors or any ability 
to catch and rethrow the exceptions so it is very possible one gets 
resource leaks and possibly more nasty errors as a result. Thus throwing 
exceptions through non-C++ code should be avoided anyway if at all 
possible. Sometimes an error flag can be used instead. Another solution 
could be to convert the C code to exception-safe C++ code.

hth
Paavo





[toc] | [prev] | [next] | [standalone]


#7887

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2011-07-16 23:59 +0200
Message-ID<ivt1ke$3k4$1@online.de>
In reply to#7885
On 2011-07-16 22:26:34 +0200, Paavo Helde said:

> Philipp Kraus <philipp.kraus@flashpixx.de> wrote in
> news:ivsj85$njn$1@online.de:
> 
>> On 2011-07-16 18:04:37 +0200, Paavo Helde said:
>> 
>>> Philipp Kraus <philipp.kraus@flashpixx.de> wrote in news:ivs5ac$c5s$1
>>> @online.de:
>>> 
>>>> I'm a little bit closer on the problem context, I have mixed C and
>>>> C++ code in the class that throws the exception.
>>> [...]
>>>> problem. I try to recompile my sources with the -fexceptions flag,
>>>> but that does not wort. Shoud I compile my C libraries with the
>>>> flag?
>>> 
>>> The -fexceptions flag should not have any effect on C++ code
>>> whatsoever. You need this for compiling any C code which is supposed
>>> to let C++ exceptions propagate through it. On Windows platform MSVC
>>> implements exceptions at the OS level so there is no such special
>>> flag needed for C code, but things may be different with cygwin or
>>> gcc.
>> 
>> I think this question is off-topic, but do you know a working solution
>> for g++? I have compiled all my libraries and my code with g++ / gcc,
>> so should I set the
>> -fexceptions flag on each library or only on my code?
> 
> I don't know if this is off-topic or not, there is too less information.
> For example it is not clear what you mean exactly by "mix of C and C++ in
> the class" and if "your code" is C or C++. Maybe you could post a minimal
> example demonstrating the problem?

It's very simple. I use the libxml2 functions for parsing XML data. The library
have some error function / callback function for detecting errors 
during the parsing.

eg:

my xmlclass {
   public:
         doxml( std::string p_xml ) {

              xmlParseMemory(p_xml.c_str)
              if (xmlErrorDetect()) {
                   xmlClear()
		throw std::runtime_error("error")
              }
         }
}

In my main function
{
	myxmlclass obj;
	try {
		obj.doxml("abcdef");
	} catch (...) {
		std::cout << "exception is caught" << std::endl;
	}
}


The calls with xml prefix are the calls of the libxml2. I have checked 
with gdb, the throw will be called, but not caught in the main. I can 
change
the (...) to anything, but I can't catch the exception. I have tested 
with std::exception, own exception, that derivated from std::exception. 
Under
the Cygwin g++ I can't catch it, same code under OSX and Linux works 
fine, the exception is caught and I can handle it.

> All I know that with Linux and gcc, all C code which has to be able to
> propagate exceptions through it must be compiled with -fexceptions.

The -fexceptions is enabled on default, so I think its correct.

I do not understand where the problem is and how I can solve it

[toc] | [prev] | [next] | [standalone]


#7888

FromPaavo Helde <myfirstname@osa.pri.ee>
Date2011-07-16 17:39 -0500
Message-ID<Xns9F2510EDAC530myfirstnameosapriee@216.196.109.131>
In reply to#7887
Philipp Kraus <philipp.kraus@flashpixx.de> wrote in
news:ivt1ke$3k4$1@online.de: 

> On 2011-07-16 22:26:34 +0200, Paavo Helde said:
> 
>> Philipp Kraus <philipp.kraus@flashpixx.de> wrote in
>> news:ivsj85$njn$1@online.de:
>> 
>>> On 2011-07-16 18:04:37 +0200, Paavo Helde said:
>>> 
>>>> Philipp Kraus <philipp.kraus@flashpixx.de> wrote in
>>>> news:ivs5ac$c5s$1 @online.de:
>>>> 
>>>>> I'm a little bit closer on the problem context, I have mixed C and
>>>>> C++ code in the class that throws the exception.
>>>> [...]
>>>>> problem. I try to recompile my sources with the -fexceptions flag,
>>>>> but that does not wort. Shoud I compile my C libraries with the
>>>>> flag?
>>>> 
>>>> The -fexceptions flag should not have any effect on C++ code
>>>> whatsoever. You need this for compiling any C code which is
>>>> supposed to let C++ exceptions propagate through it. On Windows
>>>> platform MSVC implements exceptions at the OS level so there is no
>>>> such special flag needed for C code, but things may be different
>>>> with cygwin or gcc.
>>> 
>>> I think this question is off-topic, but do you know a working
>>> solution for g++? I have compiled all my libraries and my code with
>>> g++ / gcc, so should I set the
>>> -fexceptions flag on each library or only on my code?
>> 
>> I don't know if this is off-topic or not, there is too less
>> information. For example it is not clear what you mean exactly by
>> "mix of C and C++ in the class" and if "your code" is C or C++. Maybe
>> you could post a minimal example demonstrating the problem?
> 
> It's very simple. I use the libxml2 functions for parsing XML data.
> The library have some error function / callback function for detecting
> errors during the parsing.

You mention a callback function, but there is no callback function in 
your example code. Do you use xmlSetGenericErrorFunc()? If yes, then this 
should be included in the example.

> eg:
> 
> my xmlclass {
>    public:
>          doxml( std::string p_xml ) {
> 
>               xmlParseMemory(p_xml.c_str)
>               if (xmlErrorDetect()) {
>                    xmlClear()
>           throw std::runtime_error("error")
>               }
>          }
> }
> 
> In my main function
> {
>      myxmlclass obj;
>      try {
>           obj.doxml("abcdef");
>      } catch (...) {
>           std::cout << "exception is caught" << std::endl;
>      }
> }

This code does not compile (lots of missing semicolons and other errors), 
neither does it throw exceptions through C code, so I believe it has no 
relevance to your real problem. Please post a compilable example 
demonstrating the problem!

> 
> 
> The calls with xml prefix are the calls of the libxml2. I have checked
> with gdb, the throw will be called, but not caught in the main. I can 
> change
> the (...) to anything, but I can't catch the exception. I have tested 
> with std::exception, own exception, that derivated from
> std::exception. Under
> the Cygwin g++ I can't catch it, same code under OSX and Linux works 
> fine, the exception is caught and I can handle it.
> 
>> All I know that with Linux and gcc, all C code which has to be able
>> to propagate exceptions through it must be compiled with
>> -fexceptions. 
> 
> The -fexceptions is enabled on default, so I think its correct.

AFAIK -fexceptions are not enabled by default for C code, are you sure 
that the libxml2 library has been compiled with -fexceptions?

> I do not understand where the problem is and how I can solve it

You cannot solve the problem without understanding it. Throwing 
exceptions through non-C++ code is undefined behavior, but your example 
does no such thing, so I'm not sure either where the problem is.

Cheers
Paavo


[toc] | [prev] | [next] | [standalone]


#7889

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2011-07-17 01:17 +0200
Message-ID<ivt669$6tv$1@online.de>
In reply to#7888
On 2011-07-17 00:39:51 +0200, Paavo Helde said:

> Philipp Kraus <philipp.kraus@flashpixx.de> wrote in
> news:ivt1ke$3k4$1@online.de:
> 
>> On 2011-07-16 22:26:34 +0200, Paavo Helde said:
>> 
>>> Philipp Kraus <philipp.kraus@flashpixx.de> wrote in
>>> news:ivsj85$njn$1@online.de:
>>> 
>>>> On 2011-07-16 18:04:37 +0200, Paavo Helde said:
>>>> 
>>>>> Philipp Kraus <philipp.kraus@flashpixx.de> wrote in
>>>>> news:ivs5ac$c5s$1 @online.de:
>>>>> 
>>>>>> I'm a little bit closer on the problem context, I have mixed C and
>>>>>> C++ code in the class that throws the exception.
>>>>> [...]
>>>>>> problem. I try to recompile my sources with the -fexceptions flag,
>>>>>> but that does not wort. Shoud I compile my C libraries with the
>>>>>> flag?
>>>>> 
>>>>> The -fexceptions flag should not have any effect on C++ code
>>>>> whatsoever. You need this for compiling any C code which is
>>>>> supposed to let C++ exceptions propagate through it. On Windows
>>>>> platform MSVC implements exceptions at the OS level so there is no
>>>>> such special flag needed for C code, but things may be different
>>>>> with cygwin or gcc.
>>>> 
>>>> I think this question is off-topic, but do you know a working
>>>> solution for g++? I have compiled all my libraries and my code with
>>>> g++ / gcc, so should I set the
>>>> -fexceptions flag on each library or only on my code?
>>> 
>>> I don't know if this is off-topic or not, there is too less
>>> information. For example it is not clear what you mean exactly by
>>> "mix of C and C++ in the class" and if "your code" is C or C++. Maybe
>>> you could post a minimal example demonstrating the problem?
>> 
>> It's very simple. I use the libxml2 functions for parsing XML data.
>> The library have some error function / callback function for detecting
>> errors during the parsing.
> 
> You mention a callback function, but there is no callback function in
> your example code. Do you use xmlSetGenericErrorFunc()? If yes, then this
> should be included in the example.
> 
>> eg:
>> 
>> my xmlclass {
>> public:
>> doxml( std::string p_xml ) {
>> 
>> xmlParseMemory(p_xml.c_str)
>> if (xmlErrorDetect()) {
>> xmlClear()
>> throw std::runtime_error("error")
>> }
>> }
>> }
>> 
>> In my main function
>> {
>> myxmlclass obj;
>> try {
>> obj.doxml("abcdef");
>> } catch (...) {
>> std::cout << "exception is caught" << std::endl;
>> }
>> }
> 
> This code does not compile (lots of missing semicolons and other errors),
> neither does it throw exceptions through C code, so I believe it has no
> relevance to your real problem. Please post a compilable example
> demonstrating the problem!

The original excerpt of the method is:

        xmlResetLastError();
        bool l_error = false;

        xmlGenericErrorFunc l_fptr = myclass::XMLErrorFunction; <= 
XMLErrorFunction is a static
					method of the class which is empty to supress parsing content on the CLI
        initGenericErrorDefaultFunc( &l_fptr );

        const char* l_xmlcontent = p_xml.c_str();
        xmlDocPtr l_xml          = xmlParseMemory( l_xmlcontent, 
strlen(l_xmlcontent) );
        if ((!l_xml) || (xmlGetLastError())) {
            if (l_xml)
                xmlFreeDoc( l_xml );
            xmlCleanupParser();
            throw std::runtime_error("XML data can not be parsed");  <= 
this exception is thrown, but can not be caught /
						here I have tested with std::exception, derivated exceptions...
        }


> AFAIK -fexceptions are not enabled by default for C code, are you sure
> that the libxml2 library has been compiled with -fexceptions?

I have testet with and without compiling -fexceptions, both test are 
create the same problem.

> You cannot solve the problem without understanding it. Throwing
> exceptions through non-C++ code is undefined behavior, but your example
> does no such thing, so I'm not sure either where the problem is.

I have create a class, that uses with external C includes the libxml2 
calls for parsing XML data. In this class I throw an
exception (see excerpt), which should be caught in the main. On Linux 
and OSX g++ it works, exception is thrown and caught.
On Windows (g++ under Cygwin) the exception is thrown (checked with 
gdb) but not caught. Windows creates the message:
terminate called after throwing an instance of <exception> terminate 
called recursively
The library is compiled on all three systems with gcc and my code with 
g++. All compilers are version 4.x, only the subversions
are different

Phil

[toc] | [prev] | [next] | [standalone]


#7912

FromPaavo Helde <myfirstname@osa.pri.ee>
Date2011-07-17 02:30 -0500
Message-ID<Xns9F256AD9FFD78myfirstnameosapriee@216.196.109.131>
In reply to#7889
Philipp Kraus <philipp.kraus@flashpixx.de> wrote in
news:ivt669$6tv$1@online.de: 
> 
> The original excerpt of the method is:
> 
>         xmlResetLastError();
>         bool l_error = false;
> 
>         xmlGenericErrorFunc l_fptr = myclass::XMLErrorFunction; <= 
> XMLErrorFunction is a static
>                          method of the class which is empty to supress
>                          parsing content on the CLI 
>         initGenericErrorDefaultFunc( &l_fptr );

initGenericErrorDefaultFunc() expects a normal function pointer, using a 
static class method is formally UB, though it works in most 
implementations. 

So myclass::XMLErrorFunction() is empty as you claim. Have you put some 
debug output there to see if it is really called or not.

> 
>         const char* l_xmlcontent = p_xml.c_str();
>         xmlDocPtr l_xml          = xmlParseMemory( l_xmlcontent, 
> strlen(l_xmlcontent) );
>         if ((!l_xml) || (xmlGetLastError())) {
>             if (l_xml)
>                 xmlFreeDoc( l_xml );
>             xmlCleanupParser();
>             throw std::runtime_error("XML data can not be parsed"); 
>             <= 
> this exception is thrown, but can not be caught /
>                               here I have tested with std::exception,
>                               derivated exceptions... 
>         }

According to your descriptions (still no compilable code!) there is 
nothing to do with libxml2. You just throw an exception in one function 
and attempt to catch it in the immediate caller function. If this does 
not work, this probably means that your program state is fully corrupt, 
or that you do something else illegal.

Are you sure this is the only exception being thrown? Set a breakpoint on 
throw (should be 'catch throw' or 'break __cxa_throw' in gdb) and make 
sure the excptions occur there where you think.

> On Windows (g++ under Cygwin) the exception is thrown (checked with 
> gdb) but not caught. Windows creates the message:
> terminate called after throwing an instance of <exception> terminate 
> called recursively

I think such error message typically means that an exception is thrown 
while the call stack is being unwind as a result of another exception 
throw. In your example code there is only one throw, so I guess the error 
is in the code you have left out from the example. Please post a 
compilable example demonstrating the problem 
(http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8)

p.


[toc] | [prev] | [next] | [standalone]


#7918

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2011-07-17 11:18 +0200
Message-ID<ivu9d0$nff$1@online.de>
In reply to#7912
On 2011-07-17 09:30:14 +0200, Paavo Helde said:

> Philipp Kraus <philipp.kraus@flashpixx.de> wrote in
> news:ivt669$6tv$1@online.de:
>> 
>> The original excerpt of the method is:
>> 
>> xmlResetLastError();
>> bool l_error = false;
>> 
>> xmlGenericErrorFunc l_fptr = myclass::XMLErrorFunction; <=
>> XMLErrorFunction is a static
>> method of the class which is empty to supress
>> parsing content on the CLI
>> initGenericErrorDefaultFunc( &l_fptr );
> 
> initGenericErrorDefaultFunc() expects a normal function pointer, using a
> static class method is formally UB, though it works in most
> implementations.
> 
> So myclass::XMLErrorFunction() is empty as you claim. Have you put some
> debug output there to see if it is really called or not.

Yes, I do. If I set a std::cout in the function, on an error the text is shown.

> 
>> 
>> const char* l_xmlcontent = p_xml.c_str();
>> xmlDocPtr l_xml          = xmlParseMemory( l_xmlcontent,
>> strlen(l_xmlcontent) );
>> if ((!l_xml) || (xmlGetLastError())) {
>> if (l_xml)
>> xmlFreeDoc( l_xml );
>> xmlCleanupParser();
>> throw std::runtime_error("XML data can not be parsed");
>> <=
>> this exception is thrown, but can not be caught /
>> here I have tested with std::exception,
>> derivated exceptions...
>> }
> 
> According to your descriptions (still no compilable code!) there is
> nothing to do with libxml2. You just throw an exception in one function
> and attempt to catch it in the immediate caller function. If this does
> not work, this probably means that your program state is fully corrupt,
> or that you do something else illegal.

Why is this "fully corrupt"? On different OS there is a different 
behavior, only
Windows creates a problem. It seems that the binary code under Windows
is different from the code on Linux or OSX for catching exceptions. I've tested
another example with a Boost exception (I will catch the exception of a 
lexcial cast).
Linux and OSX do it in a correct way, raises the exception and caught 
it. On Windows
the exception raises, but the catch block will be ignored and I'll get 
the error with
the "terminate line".

I don't think the code is corrupted, because on this point Linux and 
OSX should not
be work also. My question is there a compiler flag or anything else, 
that I must note
if I run code under Cygwin / Windows? Is exception calling / handling 
different than other OS?

I'm not sure, if this a problem of my code or a problem of the 
compiling / linking step or compiler?
I have tested the code on OSX 10.5, 10.6 and Linux x64 (always with g++ 
and self-build libraries)
so only on Windows x32 the problem with the exception is shown.

> Are you sure this is the only exception being thrown? Set a breakpoint on
> throw (should be 'catch throw' or 'break __cxa_throw' in gdb) and make
> sure the excptions occur there where you think.

Yes I'm sure, therefor I have checked with gdb and the __cxa_throw is show
on Windows in the gdb and with "bt" the method and exactly this throw is found.

> I think such error message typically means that an exception is thrown
> while the call stack is being unwind as a result of another exception
> throw. In your example code there is only one throw, so I guess the error
> is in the code you have left out from the example. Please post a
> compilable example demonstrating the problem
> (http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8)

I will try to create an example which demonstrate the problem. 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web