How to catch segmentation fault.
-
wrote on 29 Aug 2019, 07:43 last edited by Qingshui Kong
Hello everybody,
Could anybody help me?
Recently I am learning QT. But segmentation fault often happens. I know it's critial. But I still hope the application can continue when the error happens. I find a open source library on the Internet. It is 'segvcatch'. It works.
But unfortunately, it is said not safe. What's more, if segmentation fault happens in some sub thread, the application still crashes. That means it doesn't work for multi-thread.
So what should I do? Is there any solution for QT?
I work on Ubtuntu 16.04, and I use QT 5.9.1.
Could somebody give me any advice? Thanks in advance. -
Hello everybody,
Could anybody help me?
Recently I am learning QT. But segmentation fault often happens. I know it's critial. But I still hope the application can continue when the error happens. I find a open source library on the Internet. It is 'segvcatch'. It works.
But unfortunately, it is said not safe. What's more, if segmentation fault happens in some sub thread, the application still crashes. That means it doesn't work for multi-thread.
So what should I do? Is there any solution for QT?
I work on Ubtuntu 16.04, and I use QT 5.9.1.
Could somebody give me any advice? Thanks in advance.@qingshui-kong said in How to catch segmentation fault.:
But I still hope the application can continue when the error happens.
No. Segmentation faults are programming errors, no continuation expected.
Fix you errors and your program will run without SEGFAULTs
Regards
-
@qingshui-kong said in How to catch segmentation fault.:
But I still hope the application can continue when the error happens.
No. Segmentation faults are programming errors, no continuation expected.
Fix you errors and your program will run without SEGFAULTs
Regards
wrote on 29 Aug 2019, 07:54 last edited by@aha_1980
Thanks.
Yes, no contiuation is expected.
But could we do that as segvcatch did?
The reason is that I want to pop some message box to tell me what happens. If not, I am confused. 'What happened?' and 'Why did the application exit?' -
@aha_1980
Thanks.
Yes, no contiuation is expected.
But could we do that as segvcatch did?
The reason is that I want to pop some message box to tell me what happens. If not, I am confused. 'What happened?' and 'Why did the application exit?'@qingshui-kong said in How to catch segmentation fault.:
If not, I am confused. 'What happened?' and 'Why did the application exit?
That's what the debugger is for
-
@qingshui-kong said in How to catch segmentation fault.:
If not, I am confused. 'What happened?' and 'Why did the application exit?
That's what the debugger is for
wrote on 29 Aug 2019, 08:07 last edited by@j-hilk
Thanks.
Yes, I should debug to find out the fault.
But if the fault didn't happen before the aaplication was released. Then I released it. It happened when someone using it. The user didn't know what happened. He just thought it was a bad application and didn't want to use it any more. I don't think that is what we want. -
@j-hilk
Thanks.
Yes, I should debug to find out the fault.
But if the fault didn't happen before the aaplication was released. Then I released it. It happened when someone using it. The user didn't know what happened. He just thought it was a bad application and didn't want to use it any more. I don't think that is what we want. -
wrote on 29 Aug 2019, 08:18 last edited by
@j-hilk
Yeah, that is posted by me. That is how to debug.
But I just think it is not very good if the application crashes directly when some error occurs.
If there is no solution, maybe I should give up. -
@j-hilk
Yeah, that is posted by me. That is how to debug.
But I just think it is not very good if the application crashes directly when some error occurs.
If there is no solution, maybe I should give up.@qingshui-kong
you could try Python or Rust, you will be hard pressed to run into memory error issues with those languages. -
@j-hilk
Thanks.
Yes, I should debug to find out the fault.
But if the fault didn't happen before the aaplication was released. Then I released it. It happened when someone using it. The user didn't know what happened. He just thought it was a bad application and didn't want to use it any more. I don't think that is what we want.wrote on 29 Aug 2019, 08:36 last edited by Cobra91151Hello!
The segmentation fault must be fixed sooner or later! But in case you want to store the crash logging information.
Code:
#include <signal.h> void manageSegFailure(int signalCode); int main(int argc, char *argv[]) { QApplication app(argc, argv); signal(SIGSEGV, manageSegFailure); .... } void manageSegFailure(int signalCode) { int userResult = QMessageBox::critical(nullptr, "Error", "Unexpected error has occurred! Do you want to submit the feedback?", QMessageBox::Yes | QMessageBox::No); if (userResult == QMessageBox::Yes) { // You can store the logging info here. } signal(signalCode, SIG_DFL); QApplication::exit(3); }
The application will still crash, but before it will display the
msgbox
. Also, my code works onWindows
, I am not sure aboutUbuntu
, you have to check it there. Happy coding! -
Hello!
The segmentation fault must be fixed sooner or later! But in case you want to store the crash logging information.
Code:
#include <signal.h> void manageSegFailure(int signalCode); int main(int argc, char *argv[]) { QApplication app(argc, argv); signal(SIGSEGV, manageSegFailure); .... } void manageSegFailure(int signalCode) { int userResult = QMessageBox::critical(nullptr, "Error", "Unexpected error has occurred! Do you want to submit the feedback?", QMessageBox::Yes | QMessageBox::No); if (userResult == QMessageBox::Yes) { // You can store the logging info here. } signal(signalCode, SIG_DFL); QApplication::exit(3); }
The application will still crash, but before it will display the
msgbox
. Also, my code works onWindows
, I am not sure aboutUbuntu
, you have to check it there. Happy coding!wrote on 29 Aug 2019, 08:40 last edited by@cobra91151
OK. Thank you very much.
Yes, I tried this solution before.
1/10