| [2615] | 1 | #include "sopnamsp.h"
|
|---|
| [242] | 2 | #include "pexceptions.h"
|
|---|
| [2322] | 3 | #include <iostream>
|
|---|
| [1960] | 4 | #include <stdio.h>
|
|---|
| [3585] | 5 | #include <string.h>
|
|---|
| [242] | 6 |
|
|---|
| [3585] | 7 | /* --- Nettoyage par Reza, Mars 2009
|
|---|
| [269] | 8 | // egcs ne semble pas connaitre set_new_handler (Reza 26/04/99)
|
|---|
| [2339] | 9 | // ca ne passe plus avec SGI-CC -LANG:std $CHECK$ Reza 14/02/2003
|
|---|
| [242] | 10 | void PFailHandler(void)
|
|---|
| 11 | {
|
|---|
| 12 | set_new_handler(NULL);
|
|---|
| 13 | cerr << "Allocation exception -- out of memory" << endl;
|
|---|
| 14 | throw(AllocationError("new"));
|
|---|
| 15 | }
|
|---|
| 16 | void InitFailNewHandler()
|
|---|
| 17 | {
|
|---|
| 18 | set_new_handler(PFailHandler);
|
|---|
| 19 | }
|
|---|
| [3585] | 20 | --- FIN nettoyage */
|
|---|
| [242] | 21 |
|
|---|
| [3585] | 22 |
|
|---|
| 23 | namespace 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 |
|
|---|
| 33 | string BuildLongExceptionMessage(const char * s, const char *file, int line)
|
|---|
| [773] | 34 | {
|
|---|
| 35 | char buff[32];
|
|---|
| 36 | sprintf(buff," Line=%d", line);
|
|---|
| 37 | string rs=s;
|
|---|
| 38 | rs += " File="; rs += file; rs += buff;
|
|---|
| 39 | return(rs);
|
|---|
| 40 | }
|
|---|
| [3585] | 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 |
|
|---|
| 57 | PThrowable::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 |
|
|---|
| 64 | PThrowable::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 |
|
|---|
| 74 | PThrowable::~PThrowable() throw()
|
|---|
| 75 | {
|
|---|
| 76 | }
|
|---|
| 77 | const char* PThrowable::what() const throw()
|
|---|
| 78 | {
|
|---|
| 79 | return msg_;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | string const PThrowable::Msg() const
|
|---|
| 83 | {
|
|---|
| 84 | return (string(msg_));
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | int PThrowable::Id() const
|
|---|
| 88 | {
|
|---|
| 89 | return id_;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| [3589] | 92 | } // namespace SOPHYA
|
|---|
| 93 |
|
|---|