Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement