Commit 6ca13636 authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

FIXED exception handling

I/O exception handling is now working and error message is displayed.
+ modernized API to C++11 recommendation (no "throw" declared)
parent a863a978
......@@ -24,7 +24,7 @@
****************************************************************************/
#include "CepGenerator.h"
// CamiTK stuff
// just for CamiTK version
#include <Core.h>
// includes from std
......@@ -91,24 +91,19 @@ int main(int argc, char* argv[]) {
else {
// now we can work!
// for the translation from argument to QString, see http://qt-project.org/doc/qt-4.8/qcoreapplication.html#accessing-command-line-arguments
CepGenerator* generator = new CepGenerator(QString::fromLocal8Bit(o.file().c_str()), QString::fromLocal8Bit(o.directory().c_str()));
generator->process();
delete generator;
CepGenerator generator(QString::fromLocal8Bit(o.file().c_str()), QString::fromLocal8Bit(o.directory().c_str()));
generator.process();
}
}
}
}
catch (const cli::exception& e) {
cerr << e << endl;
std::cerr << e << std::endl;
usage(argv[0]);
return EXIT_FAILURE;
}
catch (camitk::AbortException& e) {
std::cout << argv[0] << " aborted..." << std::endl << "camitk AbortException:" << std::endl << e.what() << std::endl;
return EXIT_FAILURE;
}
catch (std::exception& e) {
std::cout << argv[0] << " aborted..." << std::endl << "std AbortException:" << std::endl << e.what() << std::endl;
std::cout << argv[0] << " aborted by std exception: " << e.what() << std::endl;
return EXIT_FAILURE;
}
catch (...) {
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- should not be suffixed with xsd otherwise xsdcxx is going to duplicate all types ! -->
<!-- merge using and manual edit -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://camitk.imag.fr/cepcoreschema"
......
......@@ -82,7 +82,7 @@ void CepGenerator::setXmlFileName(QString xmlFileName) {
QFileInfo xmlFile(xmlFileName);
if ((! xmlFile.exists()) || (! xmlFile.isFile())) {
throw "Exception from Cep generation: \n The file " + xmlFileName + " does not exist or is not a file...\n";
throw std::invalid_argument("I/O exception during CEP file generation:\nFile " + xmlFileName.toStdString() + " does not exist or is not a file...\n");
}
this->xmlFileName = xmlFile;
......@@ -93,7 +93,7 @@ void CepGenerator::setDevDirectoryName(QString devDirectoryName) {
QFileInfo devDir(devDirectoryName);
if ( ! devDir.isDir()) {
throw "Exception from Cep generation: \n The path " + devDirectoryName + " is not a directory\n";
throw std::invalid_argument("I/O exception during CEP file generation\nPath " + devDirectoryName.toStdString() + " is not a directory\n");
}
this->devDirectoryName = devDir.absoluteDir();
......@@ -101,14 +101,14 @@ void CepGenerator::setDevDirectoryName(QString devDirectoryName) {
void CepGenerator::createDomTree() {
std::cout << "Creating Dom Tree..." << std::endl;
std::string xmlFileStr = this->xmlFileName.canonicalFilePath().toStdString();
std::string xmlFileStr = xmlFileName.canonicalFilePath().toStdString();
try {
this->domCep = cep(xmlFileStr, xml_schema::flags::dont_validate);
}
catch (const xml_schema::exception& e) {
// std::cout << "Error Parsing XML file:" << std::endl;
// std::cout << e << std::endl;
std::cout << "Parsing exception during CEP file generation in XML document " << xmlFileStr << ": " << std::endl;
std::cout << e << std::endl;
throw std::invalid_argument(e.what());
}
}
......@@ -181,7 +181,7 @@ void CepGenerator::serializeManifest(QString fileName) {
QFile xmlFile(xmlFileInfo.absoluteFilePath());
if (! xmlFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
throw "Exception from cep file generation \n Cannot write on file " + xmlFileInfo.absoluteFilePath() + "\n";
throw std::invalid_argument("I/O exception during CEP file generation\nCannot write into file " + xmlFileInfo.absoluteFilePath().toStdString() + "\n");
}
// Serialization of domCep to a std::string
......@@ -230,7 +230,7 @@ void CepGenerator::generateGlobalCMakeLists() {
cmakelistsOutFileInfo.setFile(currentDirectory.absolutePath(), "CMakeLists.txt");
QFile cmakelistsOutFile(cmakelistsOutFileInfo.absoluteFilePath());
if (! cmakelistsOutFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
throw "Exception from cep file generation \n Cannot write on file " + cmakelistsOutFileInfo.absoluteFilePath() + "\n";
throw std::invalid_argument("I/O exception during CEP file generation\nCannot write into file " + cmakelistsOutFileInfo.absoluteFilePath().toStdString() + "\n");
}
QTextStream out(&cmakelistsOutFile);
......@@ -281,7 +281,7 @@ void CepGenerator::generateCopyright() {
copyrightOutFileInfo.setFile(currentDirectory.absolutePath(), "COPYRIGHT");
QFile copyrightOutFile(copyrightOutFileInfo.absoluteFilePath());
if (! copyrightOutFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
throw "Exception from cep file generation \n Cannot write on file " + copyrightOutFileInfo.absoluteFilePath() + "\n";
throw std::invalid_argument("I/O exception during CEP file generation\nCannot write into file " + copyrightOutFileInfo.absoluteFilePath().toStdString() + "\n");
}
QTextStream out(&copyrightOutFile);
......@@ -310,7 +310,7 @@ void CepGenerator::generateReadme() {
readmeOutFileInfo.setFile(currentDirectory.absolutePath(), "README");
QFile readmeOutFile(readmeOutFileInfo.absoluteFilePath());
if (! readmeOutFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
throw "Exception from cep file generation \n Cannot write on file " + readmeOutFileInfo.absoluteFilePath() + "\n";
throw std::invalid_argument("I/O exception during CEP file generation\nCannot write into file " + readmeOutFileInfo.absoluteFilePath().toStdString() + "\n");
}
QTextStream out(&readmeOutFile);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment