Skip to content
Snippets Groups Projects
Commit ae400996 authored by Stéphane Albert's avatar Stéphane Albert
Browse files

ENH: Added SystemError exception; Throw SystemError exceptions when creating Dataset directory.

parent 3239685a
No related branches found
No related tags found
No related merge requests found
...@@ -96,7 +96,7 @@ Application::LoadDatasetModel( const QString& imageFilename, ...@@ -96,7 +96,7 @@ Application::LoadDatasetModel( const QString& imageFilename,
throw; throw;
} }
return model; return model;
} }
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
// //
// System includes (sorted by alphabetic order) // System includes (sorted by alphabetic order)
#include <cerrno>
#include <exception>
// //
// ITK includes (sorted by alphabetic order) // ITK includes (sorted by alphabetic order)
...@@ -34,6 +36,7 @@ ...@@ -34,6 +36,7 @@
// //
// Monteverdi includes (sorted by alphabetic order) // Monteverdi includes (sorted by alphabetic order)
#include "mvdSystemError.h"
#include "mvdVectorImageModel.h" #include "mvdVectorImageModel.h"
namespace mvd namespace mvd
...@@ -70,7 +73,22 @@ DatasetModel ...@@ -70,7 +73,22 @@ DatasetModel
if( !pathDir.exists() ) if( !pathDir.exists() )
{ {
throw; /*
qDebug() << "System error: " << errno << " -- '" << strerror( errno ) << "'";
QString message(
QString( "'%1': %2 '%3'" )
.arg( path )
.arg( errno )
.arg( strerror( errno ) )
);
qDebug() << "std::invalid_argument(" << message << ")";
throw std::invalid_argument( message.toAscii().constData() );
*/
throw SystemError( QString( "('%1')" ).arg( path ).toAscii().constData() );
} }
if( !pathDir.exists( name ) ) if( !pathDir.exists( name ) )
...@@ -78,7 +96,9 @@ DatasetModel ...@@ -78,7 +96,9 @@ DatasetModel
isEmpty = true; isEmpty = true;
if( !pathDir.mkpath( name ) ) if( !pathDir.mkpath( name ) )
throw; {
throw SystemError( QString( "('%1')" ).arg( name ).toAscii().constData() );
}
// TODO: write empty descriptor.xml // TODO: write empty descriptor.xml
} }
......
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "mvdSystemError.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
#include <QDebug>
//
// System includes (sorted by alphabetic order)
#include <cerrno>
#include <cstring>
#include <sstream>
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
namespace mvd
{
/*
TRANSLATOR mvd::SystemError
Necessary for lupdate to be aware of C++ namespaces.
Context comment for translator.
*/
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
/*****************************************************************************/
std::string
SystemError::whatString( int err, const std::string& msg )
{
#if 0
// Use Qt's tr() in order for the text string to be translated.
// N.B.: strerror() string may use system locales.
return
( msg.empty()
? tr( "System error %1: '%2'." )
.arg( err )
.arg( strerror( err ) )
: tr( "System error %1: '%2' %3." )
.arg( err )
.arg( strerror( err ) )
.arg( msg )
).toAscii().constData();
#else
std::stringstream sstream( std::ios_base::out );
sstream
<< "System error "
<< err
<< ": "
<< strerror( err )
<< ( msg.empty()
? "."
: " " + msg + "." );
qDebug() << sstream.str().c_str();
return sstream.str();
#endif
}
/*******************************************************************************/
SystemError
::SystemError( const std::string& message ) :
std::runtime_error( SystemError::whatString( errno, message ) ),
m_Message(),
m_ErrorCode( errno )
{
qDebug() << what();
}
/*******************************************************************************/
SystemError
::SystemError( int errorCode, const std::string& message ) :
std::runtime_error( SystemError::whatString( errorCode, message ) ),
m_Message( message ),
m_ErrorCode( errorCode )
{
qDebug() << what();
}
/*******************************************************************************/
SystemError
::~SystemError()
throw()
{
}
} // end namespace 'mvd'
/*=========================================================================
Program: Monteverdi2
Language: C++
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See Copyright.txt for details.
Monteverdi2 is distributed under the CeCILL licence version 2. See
Licence_CeCILL_V2-en.txt or
http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt for more details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __mvdSystemError_h
#define __mvdSystemError_h
//
// Configuration include.
//// Included at first position before any other ones.
#include "ConfigureMonteverdi2.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
//
// System includes (sorted by alphabetic order)
#include <stdexcept>
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
//
// Monteverdi includes (sorted by alphabetic order)
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
//
// External classes pre-declaration.
namespace
{
}
namespace mvd
{
//
// Internal classes pre-declaration.
/*****************************************************************************/
/* CLASS DEFINITION SECTION */
/**
* \class SystemError
*
* \brief WIP.
*/
class Monteverdi2_EXPORT SystemError :
public std::runtime_error
{
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public methods.
public:
/** \brief Constructor. */
SystemError( const std::string& message =std::string() );
/**
*/
SystemError( int errorCode, const std::string& message =std::string() );
/** \brief Destructor. */
virtual ~SystemError() throw();
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
//
// Protected methods.
protected:
//
// Protected attributes.
protected:
/*-[ PRIVATE SECTION ]-----------------------------------------------------*/
//
// Private methods.
private:
/**
*/
static std::string whatString( int errorCode, const std::string& message );
//
// Private attributes.
private:
std::string m_Message;
int m_ErrorCode;
};
} // end namespace 'mvd'.
/*****************************************************************************/
/* INLINE SECTION */
namespace mvd
{
} // end namespace 'mvd'
#endif // __mvdSystemError_h
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