How to catch exceptions using the Qt platform yourself?

I am using boost :: date_time in my project. If the date is invalid, then the std :: out_of_range C ++ exception is thrown. In a Qt gui application on a Windows platform, it becomes an exception to SEH, so it does not catch the try and catch paradigms. How can I catch the exception platform myself?

try{
    std::string ts("9999-99-99 99:99:99.999");
    ptime t(time_from_string(ts))
}
catch(...)
{
    // doesn't work on windows
}

Editorial: If someone did not understand, I wrote another example:

Qt pro file:

TEMPLATE = app
DESTDIR  = bin
VERSION  = 1.0.0
CONFIG  += debug_and_release build_all
TARGET = QExceptExample
SOURCES += exceptexample.cpp \
           main.cpp
HEADERS += exceptexample.h

exceptexample.h

#ifndef __EXCEPTEXAMPLE_H__
#define __EXCEPTEXAMPLE_H__

#include <QtGui/QMainWindow>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
#include <stdexcept>

class PushButton;
class QMessageBox;

class ExceptExample : public QMainWindow
{
  Q_OBJECT
  public:
    ExceptExample();
    ~ExceptExample();
  public slots:
    void throwExcept();
  private:
    QPushButton * throwBtn;
};

#endif

exceptexample.cpp

#include "exceptexample.h"

ExceptExample::ExceptExample()
{
  throwBtn = new QPushButton(this);
  connect(throwBtn, SIGNAL(clicked()), this, SLOT(throwExcept()));
}

ExceptExample::~ExceptExample()
{
}

void ExceptExample::throwExcept()
{
  QMessageBox::information(this, "info", "We are in throwExcept()", 
                           QMessageBox::Ok);
  try{
    throw std::out_of_range("ExceptExample");
  }
  catch(...){
    QMessageBox::information(this, "hidden", "Windows users can't see "
                             "this message", QMessageBox::Ok);
  }
}

main.cpp

#include "exceptexample.h"
#include <QApplication>

int main(int argc, char* argv[])
{
  QApplication app(argc, argv);
  ExceptExample e;
  e.show();
  return app.exec();
}
+3
source share
1 answer

Adding a response from comments:

aschelper wrote:

Qt ++ ? , .

hoxnox (OP) :

@aschelper Qt -exceptions. . .

+4

Source: https://habr.com/ru/post/1780401/


All Articles