Ignore:
Timestamp:
Mar 5, 2009, 2:24:17 PM (17 years ago)
Author:
ansari
Message:

Ajout heritage exceptions SOPHYA de std::exception (+method what()) - nettoyage/suppression TRY/CATCH... , Reza 05/03/2009

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/pexceptions.cc

    r2615 r3585  
    33#include <iostream>
    44#include <stdio.h>
     5#include <string.h>
    56
    6 void PFailHandler(void);
    7 
     7/* --- Nettoyage par Reza, Mars 2009
    88// egcs ne semble pas connaitre set_new_handler (Reza 26/04/99)
    99// ca ne passe plus avec SGI-CC -LANG:std $CHECK$ Reza 14/02/2003
    10 #if defined( __GNUG__ ) || defined(__SGICC__)
    11 void PFailHandler(void) {}
    12 void InitFailNewHandler() {}
    13 #else
    14 
    1510void PFailHandler(void)
    1611{
     
    1914  throw(AllocationError("new"));
    2015}
    21 
    2216void InitFailNewHandler()
    2317{
    2418   set_new_handler(PFailHandler);
    2519}
    26 #endif
     20--- FIN nettoyage */
    2721
    28 string SOPHYA::BuildLongExceptionMessage(const char * s, const char *file, int line)
     22
     23namespace SOPHYA {
     24
     25/*!
     26  \ingroup BaseTools
     27  \brief Utility function for appending a file name and line number to a message
     28
     29  In practice, the macro \b PExcLongMessage(a) can be used to append file name
     30  and line number to the message a.
     31*/
     32
     33string BuildLongExceptionMessage(const char * s, const char *file, int line)
    2934{
    3035  char buff[32];
     
    3439  return(rs);
    3540}
     41
     42/*!
     43    \class PThrowable
     44    \ingroup BaseTools
     45    \brief Base exception class in Sophya, inherits from std::exception
     46
     47    This class is the ancestor class for PError and PException classes which are
     48    the base classes for all exceptions used in SOPHYA. The PThrowable class inherits
     49    from the standard c++ exception base class, std::exception and implements the what()
     50    method. A message (string/char*) passed to the constructor is kept in the exception object,
     51    and can be retrieved  using the \b what() method or \b Msg() method. An integer identifier
     52    can also be associated with the exception objet and retrieved by \b Id().
     53    The message passed to the constructor is truncated to a maximum length defined by
     54    SEXC_MAXMSGLEN (=160 characters).
     55*/
     56
     57PThrowable::PThrowable(const string& m, int ident) throw()
     58{
     59  id_ = ident;
     60  strncpy(msg_, m.c_str(), SEXC_MAXMSGLEN-1);
     61  msg_[SEXC_MAXMSGLEN-1] = '\0';
     62}
     63
     64PThrowable::PThrowable(const char* m, int ident) throw()
     65{
     66  id_ = ident;
     67  if (m!=NULL) {
     68    strncpy(msg_, m, SEXC_MAXMSGLEN-1);
     69    msg_[SEXC_MAXMSGLEN-1] = '\0';
     70  }
     71  else msg_[0] = '\0';
     72}
     73
     74PThrowable::~PThrowable() throw()
     75{
     76}
     77const char* PThrowable::what() const throw()
     78{
     79  return msg_;
     80}
     81
     82string const PThrowable::Msg() const
     83{
     84  return (string(msg_));
     85}
     86
     87int PThrowable::Id() const
     88{
     89  return id_;
     90}
     91
     92} // namespace SOPHYA
Note: See TracChangeset for help on using the changeset viewer.