From 7bda4fa3503380172fe31cb9573bdbc32f1b8fe8 Mon Sep 17 00:00:00 2001 From: andreas <andreas@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Wed, 15 Sep 2010 16:05:38 +0000 Subject: [PATCH] added more meaningfull error messages in info Import git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2702 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/info/src/info_impl.cc | 36 +++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/modules/info/src/info_impl.cc b/modules/info/src/info_impl.cc index a9726b11d..de1aeaa1f 100644 --- a/modules/info/src/info_impl.cc +++ b/modules/info/src/info_impl.cc @@ -97,12 +97,7 @@ InfoImpl::InfoImpl(const String& fname): document_("EMDataInfo"), def_list_() { - QFile file(QS(fname)); - if (!document_.setContent(&file)) { - file.close(); - throw(InfoError("QDomDocument.setContent failed")); - } - file.close(); + Import(fname); } RootPtr InfoImpl::Copy() const @@ -117,9 +112,34 @@ void InfoImpl::Import(const String& fname) { document_=QDomDocument("EMDataInfo"); QFile file(QS(fname)); - if (!document_.setContent(&file)) { + if(!file.exists()){ file.close(); - throw(InfoError("QDomDocument.setContent failed")); + throw(InfoError("File: "+fname+" doesn't exist.")); + } + QString errormessage; + int errorline,errorcolumn; + if (!document_.setContent(&file,&errormessage,&errorline,&errorcolumn)) { + file.close(); + if(file.error()){ + switch(file.error()){ + case QFile::ReadError: + throw(InfoError("Error while reading file: "+fname)); + break; + case QFile::OpenError: + throw(InfoError("File: "+fname+" could not be opened.")); + break; + case QFile::PermissionsError: + throw(InfoError("Permission error accessing file: "+fname)); + break; + default: + throw(InfoError("Unspecified error while accessing file: "+fname)); + break; + } + }else{ + std::ostringstream stream; + stream << "Error while accessing file " << fname << ": " << errormessage.toStdString() << " in line " << errorline << " column " << errorcolumn; + throw(InfoError(stream.str())); + } } file.close(); } -- GitLab