[C++-sig] [Py++] user-defined exceptions

Michał Nowotka mmmnow at gmail.com
Wed Mar 25 17:27:54 CET 2009


And one more question - what about user-defined exceptions?
Suppose I have following code from library which I cannot modify:

namespace faif

{


   class FaifException : public std::exception {

	public:

		FaifException(){}

		virtual ~FaifException() throw() {}

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

		
		virtual std::ostream& print(std::ostream& os) const throw();

	};

   class UserBreakException : public FaifException {

    public:

        UserBreakException(){}

        virtual ~UserBreakException() throw() {}

        virtual const char *what() const throw(){ return "UserBreak
exception"; }


        virtual std::ostream& print(std::ostream& os) const throw();

    };

(...)

}

This causes following warnings:

WARNING: char const * faif::UserBreakException::what() const [member function]
> warning W1046: The virtual function was declared with empty throw. Adding the ability to override the function from Python breaks the exception
> specification. The function wrapper can throw any exception. In case of exception in run-time, the behaviour of the program is undefined!

WARNING: std::ostream & faif::UserBreakException::print(std::ostream &
os) const [member function]
> warning W1049: This method could not be overriden in Python - method returns reference to local variable!

WARNING: std::ostream & faif::UserBreakException::print(std::ostream &
os) const [member function]
> warning W1046: The virtual function was declared with empty throw. Adding the ability to override the function from Python breaks the exception
> specification. The function wrapper can throw any exception. In case of exception in run-time, the behaviour of the program is undefined!

Should I exclude this declarations or there is another solution? (I am
not sure excluding it may be called 'solution'...)

BTW - Why warnings doesn't provide information form what header file
particular warning was generated?
BTW2 - How to exclude the whole class from generation?

-- 
Regards

Michał Nowotka


More information about the Cplusplus-sig mailing list