Test-error.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "error.H"
29 #include "IOstreams.H"
30 #include "dictionary.H"
31 
32 using namespace Foam;
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // Main program:
36 
37 int main(int argc, char *argv[])
38 {
40 
41  try
42  {
43  WarningInFunction << "warning 1" << endl;
44  IOWarningInFunction(Serr) << "warning 2" << endl;
45 
47 
48  IOWarningInFunction(dict) << "warning 3" << endl;
49 
50  FatalErrorInFunction << "error 1" << endl;
51  FatalErrorInFunction << "error 2" << exit(FatalError);
52  }
53  catch (Foam::error& fErr)
54  {
55  Serr<< "Caught Foam error " << fErr << nl << endl;
56  }
57 
58  return 0;
59 }
60 
61 
62 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
error.H
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Serr
OSstream Serr(cerr, "Serr")
Definition: IOstreams.H:52
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::error::throwExceptions
void throwExceptions()
Definition: error.H:121
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
dictionary.H
main
int main(int argc, char *argv[])
Definition: Test-error.C:37
IOWarningInFunction
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Definition: messageStream.H:271
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::error
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:66