|
| Exception ()=delete |
| The default constructor. More...
|
|
| Exception (const Exception &other) noexcept |
| The copy constructor (needed for clone()) More...
|
|
| Exception (const char *file, int line, const QString &msg=QString("Exception")) noexcept |
| The constructor which is used to throw an exception. More...
|
|
virtual | ~Exception () noexcept |
| The destructor. More...
|
|
const QString & | getMsg () const |
| Get the error message (translated) More...
|
|
const QString & | getFile () const |
| Get the source file where the exception was thrown. More...
|
|
int | getLine () const |
| Get the line number where the exception was thrown. More...
|
|
const char * | what () const noexcept override |
| reimplemented from std::exception::what() More...
|
|
virtual void | raise () const override |
|
virtual Exception * | clone () const override |
|
The Exception class.
This is an exception base class. It inherits from the QException class, which implements an exception class which can be transferred across threads. QException inherits from std::exception. There are several subclasses of the class Exception, see inheritance diagram.
- Note
- Exceptions must always be thrown by value and caught by (const) reference!
For more information about the QException class read the Qt documentation.
Each Exception object holds following attributes:
- a message (mMsg): error message in the user's language (can be printed directly to a QMessageBox or similar)
- the filename of the source file where the exception was thrown (mFile)
- the line number where the exception was thrown (mLine)
- Note
- Every exception will automatically print a debug message (see librepcb::Debug) of type librepcb::Debug::DebugLevel_t::Exception.
Example how to use exceptions:
void foo(int i) {
if (i < 0) {
throw Exception(__FILE__, __LINE__, tr(
"Invalid argument: %1").arg(i));
}
}
void bar() noexcept {
try {
foo(-5);
QMessageBox::critical(0, tr("Error"), e.getMsg());
}
}
Exception()=delete
The default constructor.
- Warning
- Please read the "Exception Safety" notes from the Qt Project documentation before writing source code which throws exceptions, there are some important things to know: http://qt-project.org/doc/qt-5/exceptionsafety.html