Which means the following runtime error: "terminating the call without an active exception" \ n "Aborted"

The error violated me for about two days: when I run the code, I have a "terminate called without active exception" runtime error nn Aborted, why?

I try to find the code and find a line that can exit the code "xx = new int [num]", the number in my test example is about 640,000 (64 MB of memory for the new). when I set the number much less than 10, this is fine, but this time my code will get the wrong answer.

I am trying to remove all the "try / catch", but still have this error.

Also I // all the functions that invoke the sentence "xx = new int [num]", the error still exists, and this time I find that the code may exit the normal "loop".

The whole thing was passed by the compiler, have you ever encountered this error when running your code? Thanks!

I // some delete condition and get the following error: * glibc detected * ./ESMF_RegridWeightGen: munmap_chunk (): invalid pointer: 0x00000000005cd376 *

+8
c ++ try-catch
source share
5 answers

When I saw this error, it was caused by the destruction of the stream object before the stream that it encapsulated ended.

+18
source share

I came across this when I tried to use throw; outside the catch clause. Reorganization failed and error message displayed.

+7
source share

A completion message without an active exception is a hint that at some point in your program exception handling has been violated.

Memory allocation is probably the main reason, but probably not a site error. A large distribution will throw an std :: bad_alloc exception, and this exception is not handled correctly somewhere.

To test the theory, insert a line like

throw std::logic_error("Foo"); 

above the distribution, this should also cause an error.

I came across two reasons:

  • Multithreaded mingw programs compiled without the correct flags
  • The destructor that was called as part of the stack expansion process threw an exception

You should be able to diagnose the last condition with a debugger. The stack trace of your application (for example, obtained at startup in gdb) should help a lot.

+4
source share

Like Gearoid Murphy, an error occurs when a stream object is destroyed before the stream function itself is fully executed. I found this error using the tinythread library ( http://tinythreadpp.bitsnbites.eu/ ):

Before:

 #include "tinythread.h" ... void fork_thread(void (*function_pointer)(void * arg), void * arg_pointer) { tthread::thread t(function_pointer, arg_pointer); // t is destructed here, causing the "terminate called ..." error } 

After:

 #include "tinythread.h" ... void fork_thread(void (*function_pointer)(void * arg), void * arg_pointer) { tthread::thread * t = new tthread::thread(function_pointer, arg_pointer); // now the new thread object is not destructed here, preventing // the "terminate called ..." error. Remember that because thread // object must now be destructed explicitly (ie manually) with delete // call you should store the pointer t to a vector of thread pointers // for example. } 
+2
source share

In MinGW, adding the -mthreads compiler -mthreads to gcc solves this problem.

From the gcc manual :

-mthreads

Support for threading exception handling on Mingw32. Code that relies on thread-safe exception handling should compile and link all code with the -mthreads option. When compiling, -mthreads defines -D_MT; when linking, it is linked in the special auxiliary library of flows -lmingwthrd, which clears the data of processing of exceptions of flows.

+1
source share

All Articles