1

CLion appears to be not showing me any exceptions when running my code. To test this, I've created a new project with only the following code:

#include <iostream>

int main() {
    std::cout << "--- One" << std::endl;
    throw 6;
    std::cout << "--- Two" << std::endl;
    return 0;
}

Which leads to the following output:

C:\Users\david\CLionProjects\untitled\cmake-build-debug\untitled.exe
--- One

Process finished with exit code 0

As you can see, code before the exception is executed and code following it is not executed (as you would expect). But instead of a message about the exception, it says "Process finished with exit code 0", as if no exception had occurred.

The same code compiled and executed on Ubuntu (via terminal) displayed an error message. So I assume the problem is with CLion.

How can I resolve this problem so that I can see messages for exceptions in my code?

Is there any setting that could lead to such behaviour?

I'm using CLion on Windows 10 with Cygwin. Here's a screenshot of the problem:

Here's a screenshot of the problem

LazyOne
  • 158,824
  • 45
  • 388
  • 391
David
  • 11
  • 1
  • Similar question, but is not answered: https://stackoverflow.com/questions/52623592/how-to-get-clion-to-show-exceptions. – Tsyvarev May 29 '20 at 09:55
  • If you will not get any answer in few days: make a ticket at https://youtrack.jetbrains.com/issues/CPP – LazyOne May 29 '20 at 14:50
  • 1) Which toolchain are you using to compile this? 2) Try running the executable in plain Command Prompt. – David Macek May 29 '20 at 19:36
  • I'm compiling this with Cygwin64. When I tried to run the executable in Command Prompt I got an error message because of misssing dll-files. I've solved this by adding cygwin/bin to the path variable. Now the behaviour is about the same as in Clion: code before the exception is executed and there's no error message in command prompt as well. So I assume now that the problem is rather with Cygwin than with Clion. I've tried using newer (and test) versions of g++ and gdb, but it didn't change anything. – David May 30 '20 at 20:55
  • When I debug the program in Clion, I get the following output in Debug->Console: Signal: ? (Unknown signal) Process finished with exit code 541541187 – David May 30 '20 at 21:17
  • and the following output in Debug->Debugger->GDB: [..] unset env HOME [New Thread 4596.0xeac] [New Thread 4596.0x43e0] [..] gdb: unknown target exception 0x20474343 at 0x7ff95b67a799 Thread 1 "untitled" received signal ?, Unknown signal. 0x00007ff95b67a799 in RaiseException () from /cygdrive/c/WINDOWS/System32/KERNELBASE.dll [New Thread 4596.0x425c] [Thread 4596.0x425c exited with code 541541187] [Thread 4596.0xeac exited with code 541541187] [..] [Inferior 1 (process 4596) exited with code 04021641503] – David May 30 '20 at 21:17

1 Answers1

1

Throw requires also try and catch

From: http://www.cplusplus.com/doc/tutorial/exceptions/

// exceptions
#include <iostream>
using namespace std;

int main () {
  try
  {
    throw 20;
  }
  catch (int e)
  {
    cout << "An exception occurred. Exception Nr. " << e << '\n';
  }
  return 0;
}

that compiled and run under cygwin shows:

$ g++ prova1.cc -o prova1

$ ./prova1
An exception occurred. Exception Nr. 2
matzeri
  • 8,062
  • 2
  • 15
  • 16