[C++-sig] [Py++] user-defined exceptions
Roman Yakovenko
roman.yakovenko at gmail.com
Wed Mar 25 19:11:49 CET 2009
2009/3/25 Michał Nowotka <mmmnow at gmail.com>:
> 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!
I think this one is self-explained.
> 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!
The text should be different:
This method could not be overriden in Python - method returns *non
const* reference. In such cases, Boost.Python doesn't have place to
store the temporal variables.
> 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'...)
You may ignore them.
> BTW - Why warnings doesn't provide information form what header file
> particular warning was generated?
Because there was not demand to such functionality. A patch is welcome.
> BTW2 - How to exclude the whole class from generation?
c = mb.class_( <...> )
c.exclude()
I suggest you to take a look on the following document:
http://www.language-binding.net/pyplusplus/troubleshooting_guide/exceptions/exceptions.html
HTH
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list