/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2014 OpenFOAM Foundation Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . Note Included by global/globals.C \*---------------------------------------------------------------------------*/ #include "error.H" #include "fileName.H" #include "dictionary.H" #include "JobInfo.H" #include "UPstream.H" #include "StringStream.H" #include "foamVersion.H" #include "OSspecific.H" #include "Enum.H" #include "Switch.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // const Foam::Enum < Foam::error::handlerTypes > Foam::error::handlerNames ({ { handlerTypes::DEFAULT, "default" }, { handlerTypes::IGNORE, "ignore" }, { handlerTypes::WARN, "warn" }, { handlerTypes::STRICT, "strict" }, }); // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // bool Foam::error::master(const label communicator) { // Trap negative value for comm as 'default'. This avoids direct use // of UPstream::worldComm which may have not yet been initialised return ( UPstream::parRun() ? (communicator < 0 ? UPstream::master() : UPstream::master(communicator)) : true ); } bool Foam::error::warnAboutAge(const int version) noexcept { // No warning for 0 (unversioned) or -ve values (silent versioning) return ((version > 0) && (version < foamVersion::api)); } bool Foam::error::warnAboutAge(const char* what, const int version) { // No warning for 0 (unversioned) or -ve values (silent versioning). // Also no warning for (version >= foamVersion::api), which // can be used to denote future expiry dates of transition features. const bool old = ((version > 0) && (version < foamVersion::api)); if (old) { const int months = ( // YYMM -> months (12 * (foamVersion::api/100) + (foamVersion::api % 100)) - (12 * (version/100) + (version % 100)) ); if (version < 1000) { // For things that predate YYMM versioning (eg, 240 for version 2.4) std::cerr << " This " << what << " is very old.\n" << std::endl; } else { std::cerr << " This " << what << " is " << months << " months old.\n" << std::endl; } } return old; } bool Foam::error::useAbort() { // FOAM_ABORT env set and contains bool-type value return static_cast(Switch::find(Foam::getEnv("FOAM_ABORT"))); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::error::error(const char* title) : std::exception(), messageStream(title, messageStream::FATAL), functionName_("unknown"), sourceFileName_("unknown"), sourceFileLineNumber_(0), throwing_(false), messageStreamPtr_(nullptr) {} Foam::error::error(const dictionary& errDict) : std::exception(), messageStream(errDict), functionName_(errDict.get("functionName")), sourceFileName_(errDict.get("sourceFileName")), sourceFileLineNumber_(errDict.get