Revision: 972
http://svn.sourceforge.net/pygccxml/?rev=972&view=rev
Author: roman_yakovenko
Date: 2007-04-05 11:55:54 -0700 (Thu, 05 Apr 2007)
Log Message:
-----------
updating docs
Modified Paths:
--------------
pyplusplus_dev/docs/troubleshooting_guide/exceptions/definition.rest
pyplusplus_dev/docs/troubleshooting_guide/exceptions/exceptions.cpp
pyplusplus_dev/docs/troubleshooting_guide/lessons_learned.rest
Modified: pyplusplus_dev/docs/troubleshooting_guide/exceptions/definition.rest
===================================================================
--- pyplusplus_dev/docs/troubleshooting_guide/exceptions/definition.rest 2007-04-05 17:57:40 UTC (rev 971)
+++ pyplusplus_dev/docs/troubleshooting_guide/exceptions/definition.rest 2007-04-05 18:55:54 UTC (rev 972)
@@ -1,4 +1,4 @@
-Boost.Python has a limitation: it does not allow to create classes, which derives
-from the classes defined in Python. It is impossible to solve the general use case,
-without changing the library, but it is pretty simple to create solution for
-"exception" classes.
+Boost.Python has a limitation: it does not allow to create class, which derives
+from the class defined in Python. In most use cases this should not bother you,
+except one - exceptions. The example will provide you with one of the possible
+solutions.
\ No newline at end of file
Modified: pyplusplus_dev/docs/troubleshooting_guide/exceptions/exceptions.cpp
===================================================================
--- pyplusplus_dev/docs/troubleshooting_guide/exceptions/exceptions.cpp 2007-04-05 17:57:40 UTC (rev 971)
+++ pyplusplus_dev/docs/troubleshooting_guide/exceptions/exceptions.cpp 2007-04-05 18:55:54 UTC (rev 972)
@@ -4,10 +4,14 @@
/**
* Content:
- * * example, which explain how to create custom exception class, which derives
- * from Python built-in exceptions
+ * * example, which explain how to create custom exception class, which gives
+ * expected behaviour to exceptions exposed using Boost.Python library.
+ *
+ * The example also allows you to map your exception classes to the Python
+ * built-in ones.
*
**/
+
class application_error : public std::exception{
public:
@@ -35,27 +39,32 @@
const std::string m_msg;
};
+//small dummy function that will conditionaly throws exception
void check_preconditions( bool raise_error ){
if( raise_error ){
throw application_error( "xyz" );
}
}
+//test function for custom r-value converter
std::string get_application_name( const application_error& err ){
return err.application_name();
}
namespace bpl = boost::python;
-struct exception_translator{
+struct exception_translator{
exception_translator(){
+
+ bpl::register_exception_translator<application_error>(&exception_translator::translate);
+
+ //Register custom r-value converter
+ //There are situations, where we have to pass the exception back to
+ //C++ library. This will do the trick
bpl::converter::registry::push_back( &exception_translator::convertible
, &exception_translator::construct
, bpl::type_id<application_error>() );
-
- bpl::register_exception_translator<application_error>(&exception_translator::translate);
-
}
static void
Modified: pyplusplus_dev/docs/troubleshooting_guide/lessons_learned.rest
===================================================================
--- pyplusplus_dev/docs/troubleshooting_guide/lessons_learned.rest 2007-04-05 17:57:40 UTC (rev 971)
+++ pyplusplus_dev/docs/troubleshooting_guide/lessons_learned.rest 2007-04-05 18:55:54 UTC (rev 972)
@@ -32,7 +32,12 @@
.. _`automatic conversion` : ./automatic_conversion/automatic_conversion.html
+`exceptions`_
+ .. include:: ./exceptions/definition.rest
+
+.. _`exceptions` : ./exceptions/exceptions.html
+
.. _`Py++` : ./../pyplusplus.html
.. _`pygccxml` : http://www.language-binding.net/pygccxml/pygccxml.html
.. _`SourceForge`: http://sourceforge.net/index.php
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|