Geophysical Inversion and Modelling Library v1.5.4
Loading...
Searching...
No Matches
exitcodes.h
1/******************************************************************************
2 * Copyright (C) 2007-2024 by the GIMLi development team *
3 * Carsten Rücker carsten@resistivity.net *
4 * *
5 * Licensed under the Apache License, Version 2.0 (the "License"); *
6 * you may not use this file except in compliance with the License. *
7 * You may obtain a copy of the License at *
8 * *
9 * http://www.apache.org/licenses/LICENSE-2.0 *
10 * *
11 * Unless required by applicable law or agreed to in writing, software *
12 * distributed under the License is distributed on an "AS IS" BASIS, *
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14 * See the License for the specific language governing permissions and *
15 * limitations under the License. *
16 * *
17 ******************************************************************************/
18
19#ifndef _GIMLI_EXITCODES__H
20#define _GIMLI_EXITCODES__H
21
22// http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00653.html
23// here we will define some std::exception instead if exit codes
24
25#include <stdexcept>
26
27namespace GIMLI {
28
29//#define USE_EXIT_CODES 1
30
31
32inline void throwToImplement(const std::string & errString){
33#ifndef USE_EXIT_CODES
34 throw std::length_error(errString);
35#else
36 std::cerr << errString << std::endl;
37#endif
38}
39
40inline void throwRangeError(const std::string & errString, int idx, int low, int high){
41 std::stringstream str(errString);
42 str << " " << idx << " [" << low << ".." << high << ")" << std::endl;
43#ifndef USE_EXIT_CODES
44 throw std::out_of_range(str.str());
45#else
46 std::cerr << str.str() << std::endl;
47#endif
48}
49
50inline void throwLengthError(const std::string & errString){
51#ifndef USE_EXIT_CODES
52 throw std::length_error(errString);
53#else
54 std::cerr << errString << std::endl;
55#endif
56}
57
58DLLEXPORT bool debug();
59
60inline void throwError(const std::string & errString){
61#ifndef USE_EXIT_CODES
62 if (debug()){
63 std::cerr << "Debug: " << errString << std::endl;
64 }
65 throw std::length_error(errString);
66#else
67 std::cerr << errString << std::endl;
68#endif
69}
70
71} // namespace GIMLI
72
73#endif // _GIMLI_EXITCODES__H
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24