diff --git a/cli/cli.cpp b/cli/cli.cpp index 832cd4c..5043b8a 100644 --- a/cli/cli.cpp +++ b/cli/cli.cpp @@ -8,6 +8,7 @@ #include #include +#include #if defined(PLATFORM_UNIX) #include @@ -20,6 +21,7 @@ using namespace std; using namespace std::placeholders; using namespace ConversionUtilities; +using namespace IoUtilities; using namespace Io; namespace Cli { @@ -248,20 +250,18 @@ void InteractiveCli::openFile(const string &file, bool readOnly) m_file.load(); m_currentEntry = m_file.rootEntry(); m_o << "file \"" << file << "\" opened" << endl; - } catch (ParsingException &) { + } catch (const ParsingException &) { m_o << "error occured when parsing file \"" << file << "\"" << endl; throw; - } catch (CryptoException &) { + } catch (const CryptoException &) { m_o << "error occured when decrypting file \"" << file << "\"" << endl; throw; - } catch (ios_base::failure &) { + } catch(...) { + const char *what = catchIoFailure(); m_o << "IO error occured when opening file \"" << file << "\"" << endl; - throw; - } catch (exception &) { - m_o << "an unexpected exception occured when opening file \"" << file << "\"" << endl; - terminate(); + throw ios_base::failure(what); } - } catch(exception &e) { + } catch(const std::exception &e) { if(*e.what() != 0) { m_o << e.what() << endl; } @@ -290,20 +290,18 @@ void InteractiveCli::saveFile() try { m_file.save(*m_file.password()); m_o << "file \"" << m_file.path() << "\" saved" << endl; - } catch (ParsingException &) { + } catch (const ParsingException &) { m_o << "error occured when parsing file \"" << m_file.path() << "\"" << endl; throw; - } catch (CryptoException &) { + } catch (const CryptoException &) { m_o << "error occured when encrypting file \"" << m_file.path() << "\"" << endl; throw; - } catch (ios_base::failure &) { + } catch (...) { + const char *what = catchIoFailure(); m_o << "IO error occured when saving file \"" << m_file.path() << "\"" << endl; - throw; - } catch (exception &) { - m_o << "an unexpected exception occured when saving file \"" << m_file.path() << "\"" << endl; - terminate(); + throw ios_base::failure(what); } - } catch(exception &e) { + } catch(const exception &e) { if(*e.what() != 0) { m_o << e.what() << endl; } @@ -328,12 +326,10 @@ void InteractiveCli::createFile(const string &file) m_file.generateRootEntry(); m_currentEntry = m_file.rootEntry(); m_o << "file \"" << file << "\" created and opened" << endl; - } catch (ios_base::failure &) { + } catch (...) { + const char *what = catchIoFailure(); m_o << "IO error occured when creating file \"" << file << "\"" << endl; - throw; - } catch (exception &) { - m_o << "an unexpected exception occured when creating file \"" << file << "\"" << endl; - terminate(); + throw ios_base::failure(what); } } catch(exception &e) { if(*e.what() != 0) { diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 6bc796e..09d35c2 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -380,8 +381,8 @@ bool MainWindow::openFile(const QString &path) m_file.setPath(path.toStdString()); try { m_file.open(); - } catch (const ios_base::failure &ex) { - QString errmsg = tr("An IO error occured when opening the specified file \"%1\".\n\n(%2)").arg(path, QString::fromLocal8Bit(ex.what())); + } catch (...) { + const QString errmsg = tr("An IO error occured when opening the specified file \"%1\".\n\n(%2)").arg(path, QString::fromLocal8Bit(catchIoFailure())); m_ui->statusBar->showMessage(errmsg, 5000); QMessageBox::critical(this, QApplication::applicationName(), errmsg); return false; @@ -421,12 +422,14 @@ bool MainWindow::openFile(const QString &path) QString msg; try { m_file.load(); - } catch(CryptoException &ex) { - msg = tr("The file couldn't be decrypted.\nOpenSSL error queue: %1").arg(QString::fromLocal8Bit(ex.what())); - } catch(ios_base::failure &ex) { - msg = QString::fromLocal8Bit(ex.what()); - } catch(runtime_error &ex) { - msg = tr("Unable to parse the file. %1").arg(QString::fromLocal8Bit(ex.what())); + } catch(const CryptoException &e) { + msg = tr("The file couldn't be decrypted.\nOpenSSL error queue: %1").arg(QString::fromLocal8Bit(e.what())); + } catch (...) { + try { + msg = QString::fromLocal8Bit(catchIoFailure()); + } catch(const runtime_error &e) { + msg = tr("Unable to parse the file. %1").arg(QString::fromLocal8Bit(e.what())); + } } // show a message in the error case if(!msg.isEmpty()) { @@ -483,7 +486,8 @@ void MainWindow::createFile(const QString &path, const QString &password) // create the file and show it try { m_file.create(); - } catch (const ios_base::failure) { + } catch (...) { + catchIoFailure(); QMessageBox::critical(this, QApplication::applicationName(), tr("The file %1 couldn't be created.").arg(path)); return; } @@ -662,8 +666,8 @@ bool MainWindow::askForCreatingFile() try { m_file.create(); updateWindowTitle(); - } catch (const ios_base::failure &ex) { - QMessageBox::critical(this, QApplication::applicationName(), QString::fromLocal8Bit(ex.what())); + } catch (...) { + QMessageBox::critical(this, QApplication::applicationName(), QString::fromLocal8Bit(catchIoFailure())); return false; } } @@ -750,8 +754,8 @@ bool MainWindow::saveFile() if(m_ui->actionAlwaysCreateBackup->isChecked()) { try { m_file.doBackup(); - } catch(const ios_base::failure &ex) { - QString message(tr("The backup file couldn't be created because in IO error occured: %1").arg(QString::fromLocal8Bit(ex.what()))); + } catch(...) { + QString message(tr("The backup file couldn't be created because in IO error occured: %1").arg(QString::fromLocal8Bit(catchIoFailure()))); QMessageBox::critical(this, QApplication::applicationName(), message); m_ui->statusBar->showMessage(message, 7000); return false; @@ -784,8 +788,8 @@ bool MainWindow::saveFile() m_file.save(m_file.password()[0] != 0); } catch (const CryptoException &ex) { msg = tr("The password list couldn't be saved due to encryption failure.\nOpenSSL error queue: %1").arg(QString::fromLocal8Bit(ex.what())); - } catch(const ios_base::failure &ex) { - msg = QString::fromLocal8Bit(ex.what()); + } catch(...) { + msg = QString::fromLocal8Bit(catchIoFailure()); } // show status if(!msg.isEmpty()) { @@ -813,8 +817,8 @@ void MainWindow::exportFile() QString errmsg; try { m_file.exportToTextfile(targetPath.toStdString()); - } catch (ios_base::failure &ex) { - errmsg = tr("The password list couldn't be exported. %1").arg(QString::fromLocal8Bit(ex.what())); + } catch (...) { + errmsg = tr("The password list couldn't be exported. %1").arg(QString::fromLocal8Bit(catchIoFailure())); } if(errmsg.isEmpty()) { m_ui->statusBar->showMessage(tr("The password list has been exported."), 5000); diff --git a/model/entrymodel.cpp b/model/entrymodel.cpp index b9cbcc4..5bd8a1a 100644 --- a/model/entrymodel.cpp +++ b/model/entrymodel.cpp @@ -6,6 +6,8 @@ #include +#include + #include #include #include @@ -230,7 +232,8 @@ QVariant EntryModel::data(const QModelIndex &index, int role) const entry->make(ss); string string = ss.str(); return QByteArray(string.data(), string.size()); - } catch(const ios_base::failure &) { + } catch(...) { + IoUtilities::catchIoFailure(); return false; } } @@ -293,7 +296,9 @@ bool EntryModel::setData(const QModelIndex &index, const QVariant &value, int ro newEntry->setParent(parent, row); endInsertRows(); return true; - } catch(const ios_base::failure &) {} + } catch(...) { + IoUtilities::catchIoFailure(); + } } } } diff --git a/translations/passwordmanager_de_DE.ts b/translations/passwordmanager_de_DE.ts index ce18166..f115740 100644 --- a/translations/passwordmanager_de_DE.ts +++ b/translations/passwordmanager_de_DE.ts @@ -4,7 +4,7 @@ QtGui::EntryModel - + Name @@ -231,270 +231,270 @@ - + A simple password store using AES-256-CBC encryption via OpenSSL. - + Select a password list - - + + Password Manager files (*.pwmgr);;All files (*) - + Undo stack - + An IO error occured when opening the specified file "%1". (%2) - + The file you want to load seems to be very big. Do you really want to open it? - + Opening file - + Enter the password to open the file "%1" - + A password is needed to open the file. - + The file couldn't be decrypted. OpenSSL error queue: %1 - + Unable to parse the file. %1 - + The file <i>%1</i> couldn't be created. - + A new password list has been created. - + The password list has been load. - + Exactly one fields needs to be selected (top-left corner for insertion). - + Select where you want to save the password list - + The file was not be saved. - + There is no password list opened. - + There's no account selected. - + The password file has been modified. - + Do you want to save the changes before closing? - + The password list has been closed. - + The backup file couldn't be created because in IO error occured: %1 - + Saving file - + Enter a password to save the file - + The file hasn't been saved. - + The password list couldn't be saved due to encryption failure. OpenSSL error queue: %1 - + The password list has been saved. - + Plain text document (*.txt);;All files (*.*) - + The password list couldn't be exported. %1 - + The password list has been exported. - + The currently opened file hasn't been saved yet. - - + + Add account - - + + Add category - + Enter the entry name - + new entry - + Unable to create new entry. - + You didn't enter text. - + No node element selected. - + Unable to remove the entry. - + No entry selected. - + A field has to be selected since new fields are always inserted before the currently selected field. - + No fields have been removed since there are currently no fields selected. - + No fields have been changed since there are currently no fields selected. - + Changing password - + You didn't enter a password. <strong>No encryption</strong> will be used when saving the file next time. - + The new password will be used next time you save the file. - + You aborted. The old password will still be used when saving the file next time. - + Remove entry - + Expanded by default - + Insert field - + Remove field(s) @@ -502,37 +502,37 @@ OpenSSL error queue: %1 - + Mark as password field - + Mark as normal field - + Copy - + Copy for 5 seconds - + Paste - + Open URL - + The selection is empty. diff --git a/translations/passwordmanager_en_US.ts b/translations/passwordmanager_en_US.ts index cfebc94..9855e26 100644 --- a/translations/passwordmanager_en_US.ts +++ b/translations/passwordmanager_en_US.ts @@ -4,7 +4,7 @@ QtGui::EntryModel - + Name @@ -231,270 +231,270 @@ - + A simple password store using AES-256-CBC encryption via OpenSSL. - + Select a password list - - + + Password Manager files (*.pwmgr);;All files (*) - + Undo stack - + An IO error occured when opening the specified file "%1". (%2) - + The file you want to load seems to be very big. Do you really want to open it? - + Opening file - + Enter the password to open the file "%1" - + A password is needed to open the file. - + The file couldn't be decrypted. OpenSSL error queue: %1 - + Unable to parse the file. %1 - + The file <i>%1</i> couldn't be created. - + A new password list has been created. - + The password list has been load. - + Exactly one fields needs to be selected (top-left corner for insertion). - + Select where you want to save the password list - + The file was not be saved. - + There is no password list opened. - + There's no account selected. - + The password file has been modified. - + Do you want to save the changes before closing? - + The password list has been closed. - + The backup file couldn't be created because in IO error occured: %1 - + Saving file - + Enter a password to save the file - + The file hasn't been saved. - + The password list couldn't be saved due to encryption failure. OpenSSL error queue: %1 - + The password list has been saved. - + Plain text document (*.txt);;All files (*.*) - + The password list couldn't be exported. %1 - + The password list has been exported. - + The currently opened file hasn't been saved yet. - - + + Add account - - + + Add category - + Enter the entry name - + new entry - + Unable to create new entry. - + You didn't enter text. - + No node element selected. - + Unable to remove the entry. - + No entry selected. - + A field has to be selected since new fields are always inserted before the currently selected field. - + No fields have been removed since there are currently no fields selected. - + No fields have been changed since there are currently no fields selected. - + Changing password - + You didn't enter a password. <strong>No encryption</strong> will be used when saving the file next time. - + The new password will be used next time you save the file. - + You aborted. The old password will still be used when saving the file next time. - + Remove entry - + Expanded by default - + Insert field - + Remove field(s) @@ -502,37 +502,37 @@ OpenSSL error queue: %1 - + Mark as password field - + Mark as normal field - + Copy - + Copy for 5 seconds - + Paste - + Open URL - + The selection is empty.