Files
CoolProp/include/Exceptions.h
Ian Bell 6cb4dc12f6 Remove unused heavy headers to improve compile times (#2689)
* Remove unused heavy headers to improve compile times

- Exceptions.h: replace unused <iostream> with <string> (needed for std::string)
- CPnumerics.h: add explicit <iostream> (was relying on transitive include via Exceptions.h for std::cerr)
- superancillary/superancillary.h: replace <iostream> with <cstdio>; use fprintf for debug output
- TabularBackends.h: remove unused <sstream>

<iostream> is one of the heaviest stdlib headers; removing it from widely-included
headers (Exceptions.h: ~32 dependents, superancillary.h: pulled in by AbstractState.h,
CoolPropFluid.h, Configuration.h) reduces cold build times.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Add missing <iostream> to ODEIntegrators.cpp

ODEIntegrators.cpp uses std::cout but was relying on transitive inclusion
via Exceptions.h. After removing <iostream> from Exceptions.h, this broke
compilation. Add the include directly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-22 11:14:53 -04:00

76 lines
2.1 KiB
C++

#ifndef CPEXCEPTIONS_H
#define CPEXCEPTIONS_H
#include <exception>
#include <string>
namespace CoolProp {
class CoolPropBaseError : public std::exception
{
public:
enum ErrCode
{
eNotImplemented,
eSolution,
eAttribute,
eOutOfRange,
eValue,
eWrongFluid,
eComposition,
eInput,
eNotAvailable,
eHandle,
eKey,
eUnableToLoad,
eDirectorySize
};
CoolPropBaseError(const std::string& err, ErrCode code) throw() : m_code(code), m_err(err) {}
~CoolPropBaseError() throw() {};
virtual const char* what() const throw() {
return m_err.c_str();
}
ErrCode code() {
return m_code;
}
private:
ErrCode m_code;
std::string m_err;
};
template <CoolPropBaseError::ErrCode errcode>
class CoolPropError : public CoolPropBaseError
{
public:
CoolPropError(const std::string& err = "", ErrCode ecode = errcode) throw() : CoolPropBaseError(err, ecode) {}
};
typedef CoolPropError<CoolPropBaseError::eNotImplemented> NotImplementedError;
typedef CoolPropError<CoolPropBaseError::eSolution> SolutionError;
typedef CoolPropError<CoolPropBaseError::eAttribute> AttributeError;
typedef CoolPropError<CoolPropBaseError::eOutOfRange> OutOfRangeError;
typedef CoolPropError<CoolPropBaseError::eValue> ValueError;
typedef CoolPropError<CoolPropBaseError::eKey> KeyError;
typedef CoolPropError<CoolPropBaseError::eHandle> HandleError;
typedef CoolPropError<CoolPropBaseError::eUnableToLoad> UnableToLoadError;
typedef CoolPropError<CoolPropBaseError::eDirectorySize> DirectorySizeError;
// ValueError specializations
template <CoolPropBaseError::ErrCode errcode>
class ValueErrorSpec : public ValueError
{
public:
ValueErrorSpec(const std::string& err = "", ErrCode ecode = errcode) throw() : ValueError(err, ecode) {}
};
typedef ValueErrorSpec<CoolPropBaseError::eWrongFluid> WrongFluidError;
typedef ValueErrorSpec<CoolPropBaseError::eComposition> CompositionError;
typedef ValueErrorSpec<CoolPropBaseError::eInput> InputError;
typedef ValueErrorSpec<CoolPropBaseError::eNotAvailable> NotAvailableError;
}; /* namespace CoolProp */
#endif