GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — QExceptionStream/qexceptionstream.h at master · Skycoder42/QExceptionStream
This repository was archived by the owner on Mar 4, 2023. It is now read-only.
Expand file tree/ Copy pathqexceptionstream.hMore file actions 65 lines (50 loc) · 1.34 KB / Copy pathqexceptionstream.hFile metadata and controls65 lines (50 loc) · 1.34 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 #ifndef QEXCEPTIONSTREAM_H #define QEXCEPTIONSTREAM_H #include <exception> #include <type_traits> #include <QDebug> template <typename TException> class QExceptionStream : public QDebug { static_assert(std::is_base_of<std::exception, TException>::value, "TException must implement std::exception"); Q_DISABLE_COPY(QExceptionStream) public: QExceptionStream(); ~QExceptionStream() noexcept(false); QExceptionStream<TException> &allowThrow(); QExceptionStream<TException> &disallowThrow(); private: QString _msg; bool _canThrow = true; }; #define qThrow(type) QExceptionStream<type>{} template<typename TException> QExceptionStream<TException>::QExceptionStream() : QDebug{QtDebugMsg} { QDebug tmpDbg{&_msg}; QDebug::swap(tmpDbg); //because of initialization order } template<typename TException> QExceptionStream<TException>::~QExceptionStream() noexcept(false) { { QDebug tmpDbg{QtDebugMsg}; QDebug::swap(tmpDbg); // force flushing by "destroying" the internal debug early } if(_canThrow) throw TException{std::move(_msg)}; } template<typename TException> QExceptionStream<TException> &QExceptionStream<TException>::allowThrow() { _canThrow = true; return *this; } template<typename TException> QExceptionStream<TException> &QExceptionStream<TException>::disallowThrow() { _canThrow = false; return *this; } #endif // QEXCEPTIONSTREAM_H |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |