Interior-point-optimisation  1.0-1
Interior-pointoptimisationlibrary
IPOException.hpp
Go to the documentation of this file.
1 /*
2  * $Id: IPOException.hpp 179 2014-10-21 18:42:00Z jdl3 $
3  * Copyright (C) 2008, 2010, 2013, 2014 John D Lamb
4  * Allows creation of runtime exceptions
5  *
6  * what() returns the exception message
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22 
23 #ifndef IPOEXCEPTION_H
24 #define IPOEXCEPTION_H
25 
26 #include<iostream>
27 #include<string>
28 
36 #define IPOE(message) IPOException( message, __FILE__, __LINE__ )
37 
42 #define RETHROW(function) \
43  struct { \
44  void operator()( std::string s, char const * const fileName, \
45  int const lineNumber ){ \
46  std::cerr << "Exception caught and rethrown in " \
47  << s << ", " << fileName << ":" << lineNumber \
48  << std::endl; \
49  } \
50  } rethrow_message; \
51  rethrow_message( function, __FILE__, __LINE__ ); \
52  throw;
53 
54 namespace ipo {
55 
60  class IPOException {
61  public:
68  IPOException( const std::string &exceptionMessage,
69  char const * const fileName = 0, int const lineNumber = 0 )
70  : message { exceptionMessage }{
71  if( fileName != 0 )
72  std::cerr << "IPO exception in " << fileName << ":" << lineNumber
73  << " " << exceptionMessage << std::endl;
74  }
79  const std::string &what() const {
80  return message;
81  }
82  private:
86  const std::string message;
87  };
88 
89 }
90 
91 #endif
IPOException(const std::string &exceptionMessage, char const *const fileName=0, int const lineNumber=0)
Create a new object with the given message to indicate what happened.
const std::string message
A string to hold the exception’s message.
const std::string & what() const
Returns the exception’s message.
Objects of this class are used to store information about an exception generated by ipo objects and f...
This namespace holds all the interior-point optimisation classes.
Definition: Array.hpp:28