From 9237c7411c795ab866e90e7e328300959304b95d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 18 Jan 2012 02:10:40 +0000 Subject: [PATCH] Catch exception thrown by SMF code when it cannot write to a file (#4640). git-svn-id: svn://localhost/ardour2/branches/3.0@11259 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/session_state.cc | 6 +++++- libs/evoral/evoral/SMF.hpp | 6 ++++++ libs/evoral/src/SMF.cpp | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 893f94831b..bcc37dde51 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -773,7 +773,11 @@ Session::save_state (string snapshot_name, bool pending, bool switch_to_snapshot /* tell sources we're saving first, in case they write out to a new file * which should be saved with the state rather than the old one */ for (SourceMap::const_iterator i = sources.begin(); i != sources.end(); ++i) { - i->second->session_saved(); + try { + i->second->session_saved(); + } catch (Evoral::SMF::FileError& e) { + error << string_compose ("Could not write to MIDI file %1; MIDI data not saved.", e.file_name ()) << endmsg; + } } tree.set_root (&get_state()); diff --git a/libs/evoral/evoral/SMF.hpp b/libs/evoral/evoral/SMF.hpp index 67ea42fe7d..8bd05444c4 100644 --- a/libs/evoral/evoral/SMF.hpp +++ b/libs/evoral/evoral/SMF.hpp @@ -38,7 +38,13 @@ namespace Evoral { class SMF { public: class FileError : public std::exception { + public: + FileError (std::string const & n) : _file_name (n) {} + ~FileError () throw () {} const char* what() const throw() { return "Unknown SMF error"; } + std::string file_name () const { return _file_name; } + private: + std::string _file_name; }; SMF() : _smf(0), _smf_track(0), _empty(true) {}; diff --git a/libs/evoral/src/SMF.cpp b/libs/evoral/src/SMF.cpp index ffc21a947f..b84507818c 100644 --- a/libs/evoral/src/SMF.cpp +++ b/libs/evoral/src/SMF.cpp @@ -354,11 +354,11 @@ SMF::end_write() THROW_FILE_ERROR PBD::StdioFileDescriptor d (_file_path, "w+"); FILE* f = d.allocate (); if (f == 0) { - throw FileError (); + throw FileError (_file_path); } if (smf_save(_smf, f) != 0) { - throw FileError(); + throw FileError (_file_path); } }