Commit 4809ff77 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Tomáš Oberhuber
Browse files

File exceptions replaced with ios exception.

parent c276c33c
Loading
Loading
Loading
Loading
+0 −32
Original line number Diff line number Diff line
/***************************************************************************
                          FileCloseError.h  -  description
                             -------------------
    begin                : Mar 5, 2019
    copyright            : (C) 2019 by Tomas Oberhuber et al.
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

// Implemented by: Tomas Oberhuber

#pragma once

#include <string>
#include <stdexcept>
#include <TNL/String.h>

namespace TNL {
namespace Exceptions {

class FileCloseError
   : public std::runtime_error
{
public:
   FileCloseError( const String& fileName )
   : std::runtime_error( "An error occurred when closing file " + fileName + "." )
   {}
};

} // namespace Exceptions
} // namespace TNL
+0 −32
Original line number Diff line number Diff line
/***************************************************************************
                          FileOpenError.h  -  description
                             -------------------
    begin                : Mar 5, 2019
    copyright            : (C) 2019 by Tomas Oberhuber et al.
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

// Implemented by: Tomas Oberhuber

#pragma once

#include <string>
#include <stdexcept>
#include <TNL/String.h>

namespace TNL {
namespace Exceptions {

class FileOpenError
   : public std::runtime_error
{
public:
   FileOpenError( const String& fileName )
   : std::runtime_error( "Unable to open file " + fileName + "." )
   {}
};

} // namespace Exceptions
} // namespace TNL
+16 −6
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@

#include <memory>
#include <iostream>
#include <ios>
#include <sstream>

#include <TNL/File.h>
#include <TNL/Assert.h>
@@ -19,8 +21,6 @@
#include <TNL/Exceptions/MICSupportMissing.h>
#include <TNL/Exceptions/FileSerializationError.h>
#include <TNL/Exceptions/FileDeserializationError.h>
#include <TNL/Exceptions/FileOpenError.h>
#include <TNL/Exceptions/FileCloseError.h>

namespace TNL {

@@ -45,9 +45,16 @@ inline void File::open( const String& fileName, Mode mode )
   {
      file.open( fileName.getString(), ios_mode );
   }
   catch(...)
   catch( std::ios_base::failure )
   {
      throw Exceptions::FileOpenError( fileName );
      std::stringstream msg;
      msg <<  "Unable to open file " << fileName << " ";
      if( mode & Mode::In )
         msg << " for reading.";
      if( mode & Mode::Out )
         msg << " for writting.";

      throw std::ios_base::failure( msg.str() );
   }

   this->fileName = fileName;
@@ -61,9 +68,12 @@ inline void File::close()
      {
         file.close();
      }
      catch(...)
      catch( std::ios_base::failure )
      {
         throw Exceptions::FileCloseError( fileName );
         std::stringstream msg;
         msg <<  "Unable to close file " << fileName << ".";

         throw std::ios_base::failure( msg.str() );
      }
   }
   // reset file name