From 0bd347d010d1e0c80d5957359250507732e5f60a Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 15 Apr 2016 18:23:17 +0100 Subject: [PATCH] more robust type cast in I/O functions --- lib/File.hpp | 6 ++++++ utils/sample_combine.cpp | 2 +- utils/sample_read.cpp | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/File.hpp b/lib/File.hpp index 23a6544..a8e1719 100644 --- a/lib/File.hpp +++ b/lib/File.hpp @@ -110,6 +110,12 @@ const IoT& File::getData(const std::string &name) const LATAN_ERROR(Definition, "no data with name '" + name + "' in file " + name_); } + catch(std::bad_cast) + { + LATAN_ERROR(Definition, "data with name '" + name + "' in file " + + name_ + " does not have type '" + typeid(IoT).name() + + "'"); + } } END_LATAN_NAMESPACE diff --git a/utils/sample_combine.cpp b/utils/sample_combine.cpp index 34600d4..e24c432 100644 --- a/utils/sample_combine.cpp +++ b/utils/sample_combine.cpp @@ -187,7 +187,7 @@ int main(int argc, char *argv[]) { process(outFileName, fileName, code); } - catch (bad_cast &e) + catch (Exceptions::Definition) { process(outFileName, fileName, code); } diff --git a/utils/sample_read.cpp b/utils/sample_read.cpp index c797bb7..599b4d2 100644 --- a/utils/sample_read.cpp +++ b/utils/sample_read.cpp @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) Io::save(s, copy, File::Mode::write, name); } } - catch (bad_cast &e) + catch (Exceptions::Definition) { DSample s = Io::load(fileName); string name = Io::getFirstName(fileName);