SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <QCoreApplication>
  2. #include <QDebug>
  3. #include <QException>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     QCoreApplication a(argc, argv);
  8.  
  9.     int arr[10];
  10.     try
  11.     {
  12.         arr[11] = 30;
  13.     }
  14.     catch (const std::out_of_range& e)
  15.     {
  16.         qDebug() << "Exception out of range occurred ..." << e.what();
  17.     }
  18.     catch (...)
  19.     {
  20.         qDebug() << "Unknown Exception occured...";
  21.     }
  22.  
  23.     return a.exec();
  24. }
  25.      
  26. #include <QCoreApplication>
  27. #include <QDebug>
  28. #include <QException>
  29.  
  30. class testException : public QException
  31. {
  32. public:
  33.     testException(QString const& message) :
  34.         message(message)
  35.     {}
  36.  
  37.     virtual ~testException()
  38.     {}
  39.  
  40.     void raise() const { throw *this; }
  41.     testException *clone() const { return new testException(*this); }
  42.  
  43.     QString getMessage() const {
  44.         return message;
  45.     }
  46. private:
  47.     QString message;
  48. };
  49.  
  50. int main(int argc, char *argv[])
  51. {
  52.     QCoreApplication a(argc, argv);
  53.  
  54.     try
  55.     {
  56.         // throw std::out_of_range("blah");
  57.         throw testException("blah");
  58.     }
  59.     catch (const std::out_of_range& e)
  60.     {
  61.         qDebug() << "Exception out of range occurred ...";
  62.     }
  63.     catch (...)
  64.     {
  65.         qDebug() << "Unknown Exception occured...";
  66.     }
  67.  
  68.     return a.exec();
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top