Add more/better error messages for file i/o problems.

This commit is contained in:
Jeff Young 2018-08-13 23:26:38 +01:00
parent 529521a7ba
commit 01882d3103
2 changed files with 13 additions and 17 deletions

View File

@ -514,20 +514,15 @@ void STRING_FORMATTER::StripUseless()
//-----<FILE_OUTPUTFORMATTER>----------------------------------------
FILE_OUTPUTFORMATTER::FILE_OUTPUTFORMATTER( const wxString& aFileName,
const wxChar* aMode, char aQuoteChar ):
FILE_OUTPUTFORMATTER::FILE_OUTPUTFORMATTER( const wxString& aFileName, const wxChar* aMode,
char aQuoteChar ):
OUTPUTFORMATTER( OUTPUTFMTBUFZ, aQuoteChar ),
m_filename( aFileName )
{
m_fp = wxFopen( aFileName, aMode );
if( !m_fp )
{
wxString msg = wxString::Format(
_( "cannot open or save file \"%s\"" ),
m_filename.GetData() );
THROW_IO_ERROR( msg );
}
THROW_IO_ERROR( std::strerror( errno ) );
}
@ -540,13 +535,8 @@ FILE_OUTPUTFORMATTER::~FILE_OUTPUTFORMATTER()
void FILE_OUTPUTFORMATTER::write( const char* aOutBuf, int aCount )
{
if( 1 != fwrite( aOutBuf, aCount, 1, m_fp ) )
{
wxString msg = wxString::Format(
_( "error writing to file \"%s\"" ),
m_filename.GetData() );
THROW_IO_ERROR( msg );
}
if( fwrite( aOutBuf, (unsigned) aCount, 1, m_fp ) != 1 )
THROW_IO_ERROR( std::strerror( errno ) );
}

View File

@ -148,10 +148,16 @@ bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
{
archLib->Save( false );
}
catch( ... /* IO_ERROR ioe */ )
catch( const IO_ERROR& ioe )
{
errorMsg.Printf( _( "Failed to save symbol library file \"%s\"" ), aFileName );
DisplayError( this, errorMsg );
DisplayErrorMessage( this, errorMsg, ioe.What() );
return false;
}
catch( std::exception& error )
{
errorMsg.Printf( _( "Failed to save symbol library file \"%s\"" ), aFileName );
DisplayErrorMessage( this, errorMsg, error.what() );
return false;
}