Commit 63dee9ef authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Implementing correct usage of exceptions. This means that the serrno is...

Implementing correct usage of exceptions. This means that the serrno is correctly set in the C interface now. The correct way to display an error message now is thus to first use sstrerror and then use getErrorMessage for a complement of information
parent 959cb000
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: BaseCnvSvc.cpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
* @(#)$RCSfile: BaseCnvSvc.cpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/19 16:37:14 $ $Author: sponcec3 $
*
*
*
......@@ -26,6 +26,8 @@
// Include Files
#include <map>
#include "castor/exception/Exception.hpp"
#include "castor/exception/Internal.hpp"
// Local Includes
#include "ICnvFactory.hpp"
......@@ -68,7 +70,7 @@ bool castor::BaseCnvSvc::removeConverter(const unsigned int id) {
// converter
//-----------------------------------------------------------------------------
castor::IConverter* castor::BaseCnvSvc::converter(const unsigned int objType)
throw (Exception) {
throw (castor::exception::Exception) {
// check if we have one
IConverter* conv = m_converters[objType];
if (0 != conv) return conv;
......@@ -76,20 +78,20 @@ castor::IConverter* castor::BaseCnvSvc::converter(const unsigned int objType)
const castor::ICnvFactory* fac =
castor::Converters::instance()->cnvFactory(repType(), objType);
if (0 == fac) {
Exception e;
castor::exception::Internal e;
e.getMessage() << "No factory found for object type "
<< objType << " and representation type "
<< repType() << std::endl;
throw e;
<< objType << " and representation type "
<< repType();
throw e;
}
m_converters[objType] = fac->instantiate();
if (0!= m_converters[objType]) return m_converters[objType];
// Throw an exception since we did not find any suitable converter
Exception e;
castor::exception::Internal e;
e.getMessage() << "No converter for object type "
<< objType << " and representation type "
<< repType() << std::endl;
<< repType();
throw e;
};
......@@ -100,7 +102,7 @@ void castor::BaseCnvSvc::createRep(castor::IAddress* address,
castor::IObject* object,
ObjectSet& alreadyDone,
bool autocommit)
throw (castor::Exception) {
throw (castor::exception::Exception) {
// Look for an adapted converter
IConverter* conv = converter(object->type());
// convert
......@@ -115,7 +117,7 @@ void castor::BaseCnvSvc::updateRep(castor::IAddress* address,
castor::IObject* object,
ObjectSet& alreadyDone,
bool autocommit)
throw (castor::Exception) {
throw (castor::exception::Exception) {
// Look for an adapted converter
IConverter* conv = converter(object->type());
// convert
......@@ -130,7 +132,7 @@ void castor::BaseCnvSvc::deleteRep(castor::IAddress* address,
castor::IObject* object,
ObjectSet& alreadyDone,
bool autocommit)
throw (castor::Exception) {
throw (castor::exception::Exception) {
// Look for an adapted converter
IConverter* conv = converter(object->type());
// convert
......@@ -143,7 +145,7 @@ void castor::BaseCnvSvc::deleteRep(castor::IAddress* address,
// -----------------------------------------------------------------------
castor::IObject* castor::BaseCnvSvc::createObj
(castor::IAddress* address, castor::ObjectCatalog& newlyCreated)
throw (castor::Exception) {
throw (castor::exception::Exception) {
// Look for an adapted converter
castor::IConverter* conv = converter(address->objType());
return conv->createObj(address, newlyCreated);
......
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: BaseCnvSvc.hpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
* @(#)$RCSfile: BaseCnvSvc.hpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/19 16:37:14 $ $Author: sponcec3 $
*
*
*
......@@ -33,7 +33,7 @@
// Local Includes
#include "ICnvSvc.hpp"
#include "BaseSvc.hpp"
#include "Exception.hpp"
#include "castor/exception/Exception.hpp"
#include "ObjectSet.hpp"
#include "ObjectCatalog.hpp"
......@@ -81,7 +81,7 @@ namespace castor {
* is found
*/
virtual IConverter* converter(const unsigned int objType)
throw (Exception);
throw (castor::exception::Exception);
/**
* gets the representation type, that is the type of
......@@ -105,7 +105,7 @@ namespace castor {
IObject* object,
ObjectSet& alreadyDone,
bool autocommit = false)
throw (Exception);
throw (castor::exception::Exception);
/**
* Updates foreign representation from a C++ Object.
......@@ -123,7 +123,7 @@ namespace castor {
IObject* object,
ObjectSet& alreadyDone,
bool autocommit = true)
throw (Exception);
throw (castor::exception::Exception);
/**
* Deletes foreign representation of a C++ Object.
......@@ -141,7 +141,7 @@ namespace castor {
castor::IObject* object,
castor::ObjectSet& alreadyDone,
bool autocommit = true)
throw (castor::Exception);
throw (castor::exception::Exception);
/**
* Creates C++ object from foreign representation
......@@ -158,7 +158,7 @@ namespace castor {
*/
virtual IObject* createObj (IAddress* address,
ObjectCatalog& newlyCreated)
throw (castor::Exception);
throw (castor::exception::Exception);
private:
/**
......
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: BaseObject.cpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
* @(#)$RCSfile: BaseObject.cpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/19 16:37:14 $ $Author: sponcec3 $
*
*
*
......@@ -29,13 +29,15 @@
#include "castor/Services.hpp"
#include "castor/MsgSvc.hpp"
#include "castor/BaseObject.hpp"
#include "castor/Exception.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/exception/Internal.hpp"
#include "Cglobals.h"
// -----------------------------------------------------------------------
// msgSvc
// -----------------------------------------------------------------------
castor::MsgSvc* castor::BaseObject::msgSvc() throw (castor::Exception) {
castor::MsgSvc* castor::BaseObject::msgSvc()
throw (castor::exception::Exception) {
IService* svc = svcs()->service("MsgSvc",
castor::MsgSvc::ID());
if (0 == svc) return 0;
......@@ -50,7 +52,8 @@ castor::MsgSvc* castor::BaseObject::msgSvc() throw (castor::Exception) {
//------------------------------------------------------------------------------
// svcs
//------------------------------------------------------------------------------
castor::Services* castor::BaseObject::svcs() throw (castor::Exception) {
castor::Services* castor::BaseObject::svcs()
throw (castor::exception::Exception) {
void **tls;
getTLS((void **)&tls);
if (0 == *tls) {
......@@ -62,11 +65,12 @@ castor::Services* castor::BaseObject::svcs() throw (castor::Exception) {
//------------------------------------------------------------------------------
// getTLS
//------------------------------------------------------------------------------
void castor::BaseObject::getTLS(void **thip) throw (castor::Exception) {
void castor::BaseObject::getTLS(void **thip)
throw (castor::exception::Exception) {
static int Cns_api_key = -1;
int rc = Cglobals_get (&Cns_api_key, (void **) thip, sizeof(void *));
if (*thip == NULL) {
Exception ex;
castor::exception::Internal ex;
ex.getMessage() << "Could not get thread local storage";
throw ex;
}
......@@ -78,6 +82,7 @@ void castor::BaseObject::getTLS(void **thip) throw (castor::Exception) {
//------------------------------------------------------------------------------
// clog
//------------------------------------------------------------------------------
castor::logstream& castor::BaseObject::clog() throw(castor::Exception) {
castor::logstream& castor::BaseObject::clog()
throw(castor::exception::Exception) {
return msgSvc()->stream();
}
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: BaseObject.hpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
* @(#)$RCSfile: BaseObject.hpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/19 16:37:14 $ $Author: sponcec3 $
*
* Basic object support, including pointer to Services and log support
*
......@@ -29,7 +29,7 @@
// Include Files
#include "castor/logstream.h"
#include "Exception.hpp"
#include "castor/exception/Exception.hpp"
namespace castor {
......@@ -47,7 +47,7 @@ namespace castor {
/**
* Access to the underlying Services object
*/
Services* svcs() throw(Exception);
Services* svcs() throw(castor::exception::Exception);
/**
* gets the message service.
......@@ -55,19 +55,19 @@ namespace castor {
* @return a pointer to the message service or 0 if none
* is available.
*/
MsgSvc* msgSvc() throw(Exception);
MsgSvc* msgSvc() throw(castor::exception::Exception);
/**
* Access to the log stream
*/
castor::logstream& clog() throw(Exception);
castor::logstream& clog() throw(castor::exception::Exception);
private:
/**
* gets the thread local storage
*/
void getTLS(void** thip) throw(Exception);
void getTLS(void** thip) throw(castor::exception::Exception);
}; // end of class BaseObject
......
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: BaseServer.hpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
* @(#)$RCSfile: BaseServer.hpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/19 16:37:15 $ $Author: sponcec3 $
*
*
*
......@@ -29,7 +29,7 @@
#include <iostream>
#include <string>
#include "castor/Exception.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/BaseObject.hpp"
namespace castor {
......@@ -114,7 +114,7 @@ namespace castor {
* @return a pointer to the message service or 0 if none
* is available.
*/
std::ostream& log() throw (castor::Exception);
std::ostream& log() throw (castor::exception::Exception);
/**
* Output stream to logfile
......
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: ICnvSvc.hpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
* @(#)$RCSfile: ICnvSvc.hpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/19 16:37:15 $ $Author: sponcec3 $
*
*
*
......@@ -29,7 +29,7 @@
// Include Files
#include "IService.hpp"
#include "Exception.hpp"
#include "castor/exception/Exception.hpp"
#include "ObjectSet.hpp"
#include "ObjectCatalog.hpp"
......@@ -81,7 +81,7 @@ namespace castor {
IObject* object,
ObjectSet& alreadyDone,
bool autocommit)
throw (Exception) = 0;
throw (castor::exception::Exception) = 0;
/**
* Updates foreign representation from a C++ Object.
......@@ -99,7 +99,7 @@ namespace castor {
IObject* object,
ObjectSet& alreadyDone,
bool autocommit)
throw (Exception) = 0;
throw (castor::exception::Exception) = 0;
/**
* Deletes foreign representation of a C++ Object.
......@@ -117,7 +117,7 @@ namespace castor {
castor::IObject* object,
castor::ObjectSet& alreadyDone,
bool autocommit = true)
throw (castor::Exception) = 0;
throw (castor::exception::Exception) = 0;
/**
* create C++ object from foreign representation
......@@ -134,7 +134,7 @@ namespace castor {
*/
virtual IObject* createObj (IAddress* address,
ObjectCatalog& newlyCreated)
throw (castor::Exception) = 0;
throw (castor::exception::Exception) = 0;
};
......
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: IConverter.hpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
* @(#)$RCSfile: IConverter.hpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/19 16:37:15 $ $Author: sponcec3 $
*
*
*
......@@ -31,7 +31,7 @@
#include <map>
// Local Includes
#include "Exception.hpp"
#include "castor/exception/Exception.hpp"
#include "ObjectSet.hpp"
#include "ObjectCatalog.hpp"
......@@ -76,7 +76,8 @@ namespace castor {
virtual void createRep(IAddress* address,
IObject* object,
ObjectSet& alreadyDone,
bool autocommit) throw (Exception) = 0;
bool autocommit)
throw (castor::exception::Exception) = 0;
/**
* Updates foreign representation from a C++ Object.
......@@ -93,7 +94,8 @@ namespace castor {
virtual void updateRep(IAddress* address,
IObject* object,
ObjectSet& alreadyDone,
bool autocommit) throw (Exception) = 0;
bool autocommit)
throw (castor::exception::Exception) = 0;
/**
* deletes foreign representation of a C++ Object
......@@ -110,7 +112,8 @@ namespace castor {
virtual void deleteRep(IAddress* address,
IObject* object,
ObjectSet& alreadyDone,
bool autocommit) throw (Exception) = 0;
bool autocommit)
throw (castor::exception::Exception) = 0;
/**
* create C++ object from foreign representation
......@@ -127,7 +130,7 @@ namespace castor {
*/
virtual IObject* createObj(IAddress* address,
ObjectCatalog& newlyCreated)
throw (castor::Exception) = 0;
throw (castor::exception::Exception) = 0;
};
......
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: IRequestHandler.hpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
* @(#)$RCSfile: IRequestHandler.hpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/19 16:37:15 $ $Author: sponcec3 $
*
*
*
......@@ -28,7 +28,7 @@
#define CASTOR_IREQUESTHANDLER_HPP 1
// Include Files
#include "castor/Exception.hpp"
#include "castor/exception/Exception.hpp"
namespace castor {
......@@ -51,13 +51,15 @@ namespace castor {
* forgotten whatever happens.
* @exception Exception throws an Exception in case of error
*/
virtual IAddress* nextRequestAddress() throw (Exception) = 0;
virtual IAddress* nextRequestAddress()
throw (castor::exception::Exception) = 0;
/**
* returns the number of requests handle in the database.
* @exception Exception throws an Exception in case of error
*/
virtual unsigned int nbRequestsToProcess() throw (Exception) = 0;
virtual unsigned int nbRequestsToProcess()
throw (castor::exception::Exception) = 0;
};
......
......@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# @(#)$RCSfile: Imakefile,v $ $Revision: 1.3 $ $Release$ $Date: 2004/05/17 14:46:39 $ $Author: sponcec3 $
# @(#)$RCSfile: Imakefile,v $ $Revision: 1.4 $ $Release$ $Date: 2004/05/19 16:37:16 $ $Author: sponcec3 $
#
# Make Castor libraries and executables
#
......@@ -78,7 +78,6 @@ STGLIB_OBJS = IAddressCInt.Osuf \
BaseServer.Osuf \
BaseSvc.Osuf \
Converters.Osuf \
Exception.Osuf \
Factories.Osuf \
IAddress.Osuf \
IClientCInt.Osuf \
......@@ -148,7 +147,11 @@ STGLIB_OBJS = IAddressCInt.Osuf \
stager/TpFileCopy.Osuf \
stager/TpFileCopyCInt.Osuf \
db/DbAddress.Osuf \
db/DbAddressCInt.Osuf
db/DbAddressCInt.Osuf \
exception/Exception.Osuf \
exception/InvalidArgument.Osuf \
exception/Internal.Osuf \
exception/NoEntry.Osuf
STAGEIN_OBJ = client/StageIn.Osuf
MTTEST_OBJ = client/Mttest.Osuf
......
......@@ -17,13 +17,14 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: Services.cpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
* @(#)$RCSfile: Services.cpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/19 16:37:16 $ $Author: sponcec3 $
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include "Services.hpp"
#include "Factories.hpp"
#include "Constants.hpp"
......@@ -34,6 +35,8 @@
#include "ICnvSvc.hpp"
#include "ObjectSet.hpp"
#include "ObjectCatalog.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/exception/Internal.hpp"
//-----------------------------------------------------------------------------
// Constructor
......@@ -104,7 +107,7 @@ castor::ICnvSvc* castor::Services::cnvService(const std::string name,
void castor::Services::createRep(castor::IAddress* address,
castor::IObject* object,
bool autocommit)
throw (castor::Exception) {
throw (castor::exception::Exception) {
castor::ICnvSvc* cnvSvc = cnvSvcFromAddress(address);
ObjectSet alreadyDone;
cnvSvc->createRep(address, object, alreadyDone, autocommit);
......@@ -116,7 +119,7 @@ void castor::Services::createRep(castor::IAddress* address,
void castor::Services::updateRep(castor::IAddress* address,
castor::IObject* object,
bool autocommit)
throw (castor::Exception) {
throw (castor::exception::Exception) {
castor::ICnvSvc* cnvSvc = cnvSvcFromAddress(address);
ObjectSet alreadyDone;
cnvSvc->updateRep(address, object, alreadyDone, autocommit);
......@@ -128,7 +131,7 @@ void castor::Services::updateRep(castor::IAddress* address,
void castor::Services::deleteRep(castor::IAddress* address,
castor::IObject* object,
bool autocommit)
throw (castor::Exception) {
throw (castor::exception::Exception) {
castor::ICnvSvc* cnvSvc = cnvSvcFromAddress(address);
ObjectSet alreadyDone;
cnvSvc->deleteRep(address, object, alreadyDone, autocommit);
......@@ -141,19 +144,18 @@ castor::ICnvSvc*
castor::Services::cnvSvcFromAddress(castor::IAddress* address) {
// check address
if (0 == address) {
castor::Exception ex;
ex.getMessage() << "No appropriate converter for a null address !"
<< std::endl;
castor::exception::Internal ex;
ex.getMessage() << "No appropriate converter for a null address !";
throw ex;
}
// Look for an adapted conversion service
castor::ICnvSvc *cnvSvc =
cnvService(address->cnvSvcName(), address->cnvSvcType());
if (0 == cnvSvc) {
castor::Exception ex;
castor::exception::Internal ex;
ex.getMessage() << "No conversion service with name "
<< address->cnvSvcName() << " and type "
<< address->cnvSvcType() << std::endl;
<< address->cnvSvcType();
throw ex;
}
return cnvSvc;
......@@ -163,7 +165,7 @@ castor::Services::cnvSvcFromAddress(castor::IAddress* address) {
// createObj
// -----------------------------------------------------------------------
castor::IObject* castor::Services::createObj(castor::IAddress* address)
throw (castor::Exception) {
throw (castor::exception::Exception) {
castor::ICnvSvc* cnvSvc = cnvSvcFromAddress(address);
ObjectCatalog newlyCreated;
return cnvSvc->createObj(address, newlyCreated);
......
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: Services.hpp,v $ $Revision: 1.3 $ $Release$ $Date: 2004/05/14 09:34:38 $ $Author: sponcec3 $
* @(#)$RCSfile: Services.hpp,v $ $Revision: 1.4 $ $Release$ $Date: 2004/05/19 16:37:16 $ $Author: sponcec3 $
*
*
*
......@@ -29,7 +29,7 @@
//Include Files
#include <map>
#include "Exception.hpp"
#include "castor/exception/Exception.hpp"
namespace castor {
......@@ -85,7 +85,8 @@ namespace castor {
*/
void createRep(IAddress* address,
IObject* object,
bool autocommit = true) throw (Exception);
bool autocommit = true)
throw (castor::exception::Exception);
/**
* Updates foreign representation from a C++ Object.
......@@ -101,7 +102,8 @@ namespace castor {
*/
void updateRep(IAddress* address,
IObject* object,
bool autocommit = true) throw (Exception);
bool autocommit = true)
throw (castor::exception::Exception);
/**
* deletes foreign representation of a C++ Object
......@@ -114,7 +116,8 @@ namespace castor {
*/
void deleteRep(IAddress* address,
IObject* object,
bool autocommit = false) throw (Exception);
bool autocommit = false)
throw (castor::exception::Exception);
/**
* create C++ object from foreign representation
......@@ -125,7 +128,8 @@ namespace castor {
* for the deallocation of the newly created object
* @exception Exception throws an Exception in cas of error
*/
IObject* createObj(IAddress* address) throw (Exception);
IObject* createObj(IAddress* address)
throw (castor::exception::Exception);
private:
/**
......
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: ServicesCInt.cpp,v $ $Revision: 1.6 $ $Release$ $Date: 2004/05/14 14:11:24 $ $Author: sponcec3 $
* @(#)$RCSfile: ServicesCInt.cpp,v $ $Revision: 1.7 $ $Release$ $Date: 2004/05/19 16:37:16 $ $Author: sponcec3 $
*
*
*
......@@ -25,10 +25,11 @@
*****************************************************************************/
// C++ Include Files
#include "castor/Services.hpp"
#include <string>
#include <iostream>
#include <errno.h>
#include <serrno.h>
#include "castor/Services.hpp"
#include "castor/exception/Exception.hpp"
extern "C" {
......@@ -59,8 +60,8 @@ extern "C" {
int C_Services_delete(C_Services_t* svcs) {
try {
if (0 != svcs->svcs) delete svcs->svcs;
} catch (castor::Exception e) {
errno = EINVAL;
} catch (castor::exception::Exception e) {
serrno = e.code();
svcs->errorMsg = e.getMessage().str();
return -1;
}
......@@ -82,8 +83,8 @@ extern "C" {
}
try {
svcs->svcs->createRep(address, object, autocommit);
} catch (castor::Exception e) {
errno = EINVAL;
} catch (castor::exception::Exception e) {
serrno = e.code();
svcs->errorMsg = e.getMessage().str();