-// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// Module : SALOME
// $Header$
//
-#if !defined( __Utils_SALOME_Exception_hxx__ )
-#define __Utils_SALOME_Exception_hxx__
+#pragma once
-//#include "SALOME_Utils.hxx"
-
-# include <exception>
-# include <iostream>
+#include <exception>
+#include <sstream>
+#include <string>
#ifdef LOCALIZED
#undef LOCALIZED
#endif
#if defined(_DEBUG_) || defined(_DEBUG)
-# define LOCALIZED(message) #message , __FILE__ , __LINE__
+#define LOCALIZED(message) #message, __FILE__, __LINE__
#else
-# define LOCALIZED(message) #message
+#define LOCALIZED(message) #message
#endif
//swig tool on Linux doesn't pass defines from header SALOME_Utils.hxx
//therefore (temporary solution) defines are placed below
#ifdef WIN32
-# if defined UTILS_EXPORTS || defined OpUtil_EXPORTS
-# define UTILS_EXPORT __declspec( dllexport )
-# else
-# define UTILS_EXPORT __declspec( dllimport )
-# undef LOCALIZED
-# define LOCALIZED(message) #message
-# endif
+#if defined UTILS_EXPORTS || defined OpUtil_EXPORTS
+#define UTILS_EXPORT __declspec(dllexport)
+#else
+#define UTILS_EXPORT __declspec(dllimport)
+#undef LOCALIZED
+#define LOCALIZED(message) #message
+#endif
#else
-# define UTILS_EXPORT
+#define UTILS_EXPORT
#endif
class SALOME_Exception;
-UTILS_EXPORT std::ostream& operator<<( std::ostream&, const SALOME_Exception& );
+UTILS_EXPORT std::ostream &operator<<(std::ostream &, const SALOME_Exception &);
-UTILS_EXPORT const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber );
+UTILS_EXPORT std::string makeText(const char *text, const char *fileName, const unsigned int lineNumber);
class UTILS_EXPORT SALOME_Exception : public std::exception
{
+protected:
+ std::string _text;
+public:
+ SALOME_Exception() = delete;
+ SALOME_Exception(const std::string& text):_text(text) { }
+ SALOME_Exception(const char *text, const char *fileName = nullptr, const unsigned int lineNumber = 0);
+ virtual ~SALOME_Exception() noexcept;
+ UTILS_EXPORT friend std::ostream &operator<<(std::ostream &os, const SALOME_Exception &ex);
+ virtual const char *what(void) const noexcept;
+};
-private :
- SALOME_Exception( void );
-
-protected :
- const char* _text ; // non constant pointer but read only char variable
-
-public :
- SALOME_Exception( const char *text, const char *fileName=0, const unsigned int lineNumber=0 );
- SALOME_Exception( const SALOME_Exception &ex );
- virtual ~SALOME_Exception() throw ();
- UTILS_EXPORT friend std::ostream & operator<<( std::ostream &os , const SALOME_Exception &ex );
- virtual const char *what( void ) const throw () ;
-} ;
-
-
-#endif /* #if !defined( __Utils_SALOME_Exception_hxx__ ) */
+#define THROW_SALOME_EXCEPTION(text) \
+{ \
+ std::ostringstream oss; oss << text; \
+ throw SALOME_Exception(oss.str()); \
+}