Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"throw" crashes program, but compiles fine

Tags:

c++

gcc

My program compiles fine, but crashes everytime throw (not inside of a try...catch block) is called.

Here are the command like arguments used for all files in the project:

mingw32-g++.exe -fexceptions -DWIN32 -D_WINDOWS -D_MBCS -DNO_SOCKLEN_T -DDONTUSEMEMMANAGER -Wall -g -W -fexceptions -DDEBUG

(I know that Wall makes W unnecessary and that I have -fexceptions in there twice.)

edit: I know that the there's actually nothing wrong with that behaviour. the thing is, it used to work aka the program wouldn't crash. but some days ago I made a change to some of the files , compiled again and all of a sudden it crashed

like image 845
Nik Avatar asked Jan 26 '26 20:01

Nik


2 Answers

Well, this is the expected behavior. The standard says [except.handle]:

If no matching handler is found, the function std::terminate() is called; [...]

like image 96
Yakov Galka Avatar answered Jan 28 '26 12:01

Yakov Galka


That is called an unhandled exception. The expected behavior is that the program should exit.

like image 31
Daniel A. White Avatar answered Jan 28 '26 12:01

Daniel A. White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!