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
This commit is contained in:
Carl Hetherington 2012-01-18 02:10:40 +00:00
parent f9a3f741bf
commit 9237c7411c
3 changed files with 13 additions and 3 deletions

View file

@ -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());

View file

@ -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) {};

View file

@ -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);
}
}