Program Listing for File Error.h

Return to documentation for file (/home/kpenev/projects/git/poet/poet_src/Core/Error.h)

#ifndef __ERROR_H
#define __ERROR_H

#include "../Core/SharedLibraryExportMacros.h"
#include <iostream>
#include <exception>
#include <string>

namespace Core {

    namespace Error {

        class LIB_PUBLIC General : public std::exception {
        private:
            std::string message;
        public:
            General(const std::string &error_message="") :
                message(error_message)
                {
                    std::cerr << what() << ": " << error_message << std::endl;
                }

            virtual const char *what() const throw() {return "general error";}

            const std::string &get_message() {return message;}

            virtual ~General() throw() {}
        };

        class LIB_PUBLIC ALGLIB : public General {
        public:
            ALGLIB(const std::string &error_message="") :
                General(error_message) {}

            virtual const char *what() const throw()
            {return "ALGLIB error";}
        };

        class LIB_PUBLIC Runtime : public General {
        public:
            Runtime(const std::string &error_message="") :
                General(error_message) {}

            virtual const char *what() const throw()
            {return "Run time error";}
        };

        class LIB_PUBLIC BadFunctionArguments : public Runtime {
        public:
            BadFunctionArguments(const std::string &error_message="") :
                Runtime(error_message) {
                }

            virtual const char *what() const throw()
            {return "Bad function arguments";}
        };

        class LIB_PUBLIC BadStellarZone : public BadFunctionArguments {
        public:
            BadStellarZone(const std::string &error_message="") :
                BadFunctionArguments(error_message) {}

            virtual const char *what() const throw()
            {return "Invalid stellar zone";}
        };

        class LIB_PUBLIC PathNotFound : public Runtime {
        private:
            bool directory;
        public:
            PathNotFound(const std::string &message,
                         const std::string &filename="",
                         bool isdir=false) :
                Runtime(filename+", "+message), directory(isdir) {}

            virtual const char *what() const throw() {
                return (directory ?
                        "Directory not found." :
                        "File not found.");
            }
        };

        class LIB_PUBLIC IO : public Runtime {
        public:
            IO(const std::string &filename="",
               const std::string &error_message="") :
                Runtime("Error reading "+filename+", "
                        +error_message) {}
            virtual const char *what() const throw() {return "I/O error";}
        };

        class LIB_PUBLIC CommandLine : public Runtime {
        public:
            CommandLine(const std::string &error_message="") :
                Runtime(error_message) {}

            virtual const char *what() const throw()
            {return "Error parsing the command line";}
        };

        class LIB_PUBLIC NotImplemented : public Runtime {
        public:
            NotImplemented(const std::string &feature_name="") :
                Runtime(feature_name+" not implemented yet") {}

            virtual const char *what() const throw()
            {return "Not implemented";}
        };

        class LIB_PUBLIC GSLZeroStep : public Runtime {
        public:
            GSLZeroStep(const std::string &gsl_step_type) :
                Runtime("GSL "+gsl_step_type+" step size control requires zero "
                        "step size, aborting!") {}

            virtual const char *what() const throw()
            {return "Tiny step";}
        };

        class LIB_PUBLIC NonGSLZeroStep : public Runtime {
        public:
            NonGSLZeroStep() :
                Runtime("Breaking due to condtions or NaNs has decreased "
                        "maximum step size to zero! Aborting") {}

            virtual const char *what() const throw()
            {return "Tiny step";}
        };

    } //End Error namespace.

} //End Core namespace.

#endif