XCODE produces Segmentation fault as opposed to Exception - c++

I have a very basic C++ program :-
#include <iostream>
#include <stdexcept>
int main(int argc, const char * argv[])
{
std::cout <<"Welcome .. "<<std::endl;
try {
throw std::runtime_error(std::string("Crazy exception"));
}
catch(std::exception& e) {
std::cerr << "error: " << e.what() << "\n";
exit(0);
} return 0;
}
Whenver I run this program, instead of an exception I see a Segmentation fault: 11
On the debugger, I see EXC_BAD_ACCESS(code=EXC_I386_GPFLT) at the throw statement.
I have exceptions enabled on XCODE. Has anyone ever seen this kind of basic error ?
This is really killing me, should I re-install XCODE ? If yes, what's the way for clean install or something
Re-installed XCODE directly from APP STORE. Same issue !! Next is what ? Re-install the whole OSX i believe. Can someone give some clue what "can" be tried before I lounge into a brainless reformatting of the machine ?

Yes, I have executed this program on my mac and it compiled successfully using every type of runtime error in <stdexcept>. Which version of Xcode are you running? is it installed from the Apple store or some other website?
If you have installed it from Apple store please update Xcode version to Xcode 8.3.3 and run the code again.
In case you are using it from some other website, then there is a chance that it has a bug. I have also encountered a similar problem before.
There is a simple way to uninstall Xcode from your Mac. Drag Xcode from Finder in Applications and throw it in the Trash and Empty the Trash.

Re installed MAC OSX ! And it fixed the issue.
Surprisingly there can be some OS corruption which may cause this.
Hopefully this would help someone else in future

Related

Eclipse debugger not working - automatically terminating (MingGW) CDT

I'm attempting to debug a simple application in CDT using the MinGW, i.e. Hello World.
It builds and runs correctly;
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl;
return 0;
}
With the following options:
However, when I run the debugger, it simply jumps over any breakpoints with no output, errors or stopping whatsoever (making me think that it hasn't actually run at all) straight to: terminated
Any ideas whats causing this and how I can go about fixing it?
Thanks very much!
David
UPDATES
I don't think it can be an error with GDB? As when when run from the cmd line it appears to work correctly.

C++ run error when using endl

I've recently started to learn C++ and I'm trying to compile and run a very simple program.
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
cout << "Hello Again!";
return 0;
}
The program itself compiles as it should without any errors, however, when the program runs, it seems to stop after cout << "Hello World!" << endl;. I find this very strange, as my friend is sitting right beside me, doing the exact same thing and it works for him. The same thing happens when I try to use the sizeof();; it does not return any value, however, when my friend does this, it works.
When I ran it in NetBeans, it first generated the error
RUN FAILED (exit value 255, total time: 2s)
And another time I ran it, it generated the same error, but with a different exit value. Although it is now back to 255.
When running debugger in NetBeans it produces
SIGILL (Illegal instruction)
a few times before it stops working.
I have installed the MinGW compiler at the default directory (C:\MinGW), and this is the compiler that NetBeans and any other program is using. I have also added the path to the System Environment Variables at the end of the "Path" variable:
;C:\MinGW\bin;C:\MinGW\msys\1.0\bin
Trying to run and compile the same code in Atom results in
Hello World!Press any key to continue . . .
I have tried reinstalling the compiler, and restarted my computer. None of which seems to work. I've also tried \n, which works.
My question is, is there anything wrong with my compiler or computer, or am I missing something obvious? And is it possible to fix this?
(Sorry if this is a duplicate, I've searched for a few hours, not able to find anything useful)
I found the culprit!
In my System Environment Variables, C:\MingGW\bin and C:\MingGW\MSYS\1.0\bin was at the bottom of the list. This meant that it was below C:\Program Files (x86)\GNU\GnuPG\pub (Which I think, if I'm not mistaken is another compiler).
Although all paths in NetBeans were correct, it seems like the system didn't like it when another compiler was listed above MinGW.
I solved the problem by moving the paths for MinGW up, above the GNU.

IDE showing blank console

It's been days since I try to make my IDE (Code::Blocks version 13.12, I tried on 10.05 too) work. Any program (including a simple Hello World! program) I would make would show a black console showing nothing but an " _ ". I have made an exception in my antivirus (Avast!) for the file containing the IDE) but the same thing happens . I have tried re-installing twice, i have tried resetting the compiler and debugger's settings to default, auto-detecting toolchain executables ,but the same thing happens.
I have tried rebooting my computer several times, same thing happens.
I would like to know what I can do to solve this problem , because I don't want to get another complicated compiler (I am a beginner,) , as Code::Blocks fits my needs perfectly.
The following codes produces a blank console:
#include <iostream>
int main()
{
std::cout << "Hello world!\n";
return 0;
}
I had the same exact problem, with Eclipse, Visual Studio and then with Code::Blocks (I tested them all). I suggest you follow this video tutorial after you confirm the problem persists with a second IDE : https://www.youtube.com/watch?v=zOGU8fC3bvU&index=6&list=LLHcXdIeBMN4XYRZAk4IeXmg&spfreload=10 . It will take you step by step on how to install a given compiler.

Application is Stuck on Build/Run Process

I am using Netbeans 6.8 and trying to run a simple application, here is my code:
#include <iostream>
int main()
{
std::cout<< "Game Over!" << std::endl; // Displays "Game Over" Output
return 0;
}
Netbeans says there are no errors and it cleans and builds just fine but when I click Build/Run it seems to get stuck. I literally went to the supermarket and returned to find that my program still hadn't run.
Any ideas on what the problem could be and how to fix it would be a big help, thanks.
I doubt it's the program cause this. Try finding the executable and running in on the command line and seeing if it hangs.

C++ HelloWorld not printing correctly

I just installed c/c++ development tools for my eclipse and everything is working except no text is being printed in the console when I run the hello world program, but I receive no errors. I'm really stumped, anyone know why this is?
Edit:
Ok I realized if that debug it, it works correctly, but not if I run it, any ideas there?
Are you using a 64-bit version of Eclipse? If so, that might be your problem. The 64-bit version doesn't do console output. sigh Try downgrading to the 32-bit version.
On SO, check this question.
On the Eclipse forums, check this thread.
Does a window pop up then disappear? It could be printing it in console then closing as soon as it hits the end of the code...
try to make your code like this:
#include <iostream>
#include <conio.h>
using namespase std;
int main()
{
cout << "helllo, world" << endl;
getch();
return 0;
}
You must set the environment so the eclipse can find the c++ compiler.
Go to Computer and right click Properties -> advanced system settings -> enviroment variables.
Scroll down in system variables and find the path (it is named so). Press edit and append in the path the value C:\MinGW\bin;C:\MinGW\msys\1.0\bin;. You will have something like C:\MinGW\bin;C:\MinGW\msys\1.0\bin;C:\programfiles........
Then start again the eclipse the problem should have been solved.