Pteros  2.0
Molecular modeling library for human beings!
pteros_error.h
1 /*
2  *
3  * This source code is part of
4  * ******************
5  * *** Pteros ***
6  * ******************
7  * molecular modeling library
8  *
9  * Copyright (c) 2009-2013, Semen Yesylevskyy
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of Artistic License:
13  *
14  * Please note, that Artistic License is slightly more restrictive
15  * then GPL license in terms of distributing the modified versions
16  * of this software (they should be approved first).
17  * Read http://www.opensource.org/licenses/artistic-license-2.0.php
18  * for details. Such license fits scientific software better then
19  * GPL because it prevents the distribution of bugged derivatives.
20  *
21 */
22 
23 #ifndef PERROR_H
24 #define PERROR_H
25 
26 #include <sstream>
27 #include <iostream>
28 #include <exception>
29 
30 namespace pteros {
31 
33 class Pteros_error {
34 public:
35 
36  Pteros_error(const Pteros_error& p){
37  text.str(p.text.str());
38  }
39 
40  Pteros_error(){
41  text.str("");
42  }
43 
45  Pteros_error(std::string s){
46  text.str(s);
47  }
48 
56  template<class T>
58  text << data; //Collect data
59  return *this;
60  };
61 
63  void print() const {
64  std::cout << std::endl << "PTEROS terminated due to the following error:"
65  << std::endl << text.str() << std::endl;
66  }
67 
69  std::string what() const {
70  return text.str();
71  }
72 
73 private:
74  std::stringstream text;
75 };
76 
77 }
78 #endif
std::string what() const
Return error message as string.
Definition: pteros_error.h:69
Pteros namespace.
Definition: options.cpp:32
void print() const
Print error message.
Definition: pteros_error.h:63
Pteros_error(std::string s)
Constructs an exception object with text message.
Definition: pteros_error.h:45
Pteros_error & operator<<(T data)
Operator << allows constructing error strings on the fly like this:
Definition: pteros_error.h:57
Represents an error in the Pteros code. Used for all Pteros-related exceptions.
Definition: pteros_error.h:33