Skip to content
Snippets Groups Projects
Commit 0b81f7e7 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Tomáš Oberhuber
Browse files

Added FileOpenError exception.

parent 2c8f1be7
No related branches found
No related tags found
1 merge request!29Revision
/***************************************************************************
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
......@@ -23,7 +23,7 @@ class NotTNLFile
{
public:
NotTNLFile()
: std::runtime_error( "Wring magic number found in a binary file. It is not TNL compatible file." )
: std::runtime_error( "Wrong magic number found in a binary file. It is not TNL compatible file." )
{}
};
......
......@@ -19,6 +19,7 @@
#include <TNL/Exceptions/MICSupportMissing.h>
#include <TNL/Exceptions/FileSerializationError.h>
#include <TNL/Exceptions/FileDeserializationError.h>
#include <TNL/Exceptions/FileOpenError.h>
namespace TNL {
......@@ -39,18 +40,16 @@ inline bool File::open( const String& fileName, Mode mode )
if( mode & Mode::Append ) ios_mode |= std::ios::app;
if( mode & Mode::AtEnd ) ios_mode |= std::ios::ate;
if( mode & Mode::Truncate ) ios_mode |= std::ios::trunc;
file.open( fileName.getString(), ios_mode );
/*if( mode == Mode::In )
file.open( fileName.getString(), std::ios::binary | std::ios::in );
else
file.open( fileName.getString(), std::ios::binary | std::ios::out );*/
try
{
file.open( fileName.getString(), ios_mode );
}
catch(...)
{
throw Exceptions::FileOpenError( fileName );
}
this->fileName = fileName;
if( ! file.good() ) {
std::cerr << "I am not able to open the file " << fileName << ". ";
return false;
}
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment