diff options
| author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2009-08-18 20:56:02 +0000 |
|---|---|---|
| committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-25 16:59:08 +0000 |
| commit | 9f8a09ed743cedd9547bf0661d518647966ab114 (patch) | |
| tree | 9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Examples/test-suite/director_exception.i | |
| download | swig-tarball-master.tar.gz | |
Imported from /srv/lorry/lorry-area/swig-tarball/swig-1.3.40.tar.gz.HEADswig-1.3.40master
Diffstat (limited to 'Examples/test-suite/director_exception.i')
| -rw-r--r-- | Examples/test-suite/director_exception.i | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/Examples/test-suite/director_exception.i b/Examples/test-suite/director_exception.i new file mode 100644 index 0000000..de0ef33 --- /dev/null +++ b/Examples/test-suite/director_exception.i @@ -0,0 +1,112 @@ +%module(directors="1") director_exception + +%{ + +#if defined(_MSC_VER) + #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif + +#include <string> + + +// define dummy director exception classes to prevent spurious errors +// in target languages that do not support directors. + +#ifndef SWIG_DIRECTORS +namespace Swig { +class DirectorException {}; +class DirectorMethodException: public Swig::DirectorException {}; +} + #ifndef SWIG_fail + #define SWIG_fail + #endif +#endif /* !SWIG_DIRECTORS */ + +%} + +%include "std_string.i" + +#ifdef SWIGPYTHON + +%feature("director:except") { + if ($error != NULL) { + throw Swig::DirectorMethodException(); + } +} + +%exception { + try { $action } + catch (Swig::DirectorException &) { SWIG_fail; } +} + +#endif + +#ifdef SWIGRUBY + +%feature("director:except") { + throw Swig::DirectorMethodException($error); +} + +%exception { + try { $action } + catch (Swig::DirectorException &e) { rb_exc_raise(e.getError()); } +} + +#endif + +%feature("director") Foo; + +%inline { + +class Foo { +public: + virtual ~Foo() {} + virtual std::string ping() { return "Foo::ping()"; } + virtual std::string pong(int val=3) { return "Foo::pong();" + ping(); } +}; + +Foo *launder(Foo *f) { + return f; +} + +} + + +%{ + struct Unknown1 + { + }; + + struct Unknown2 + { + }; +%} + +%feature("director") Bar; + + +%inline %{ + struct Exception1 + { + }; + + struct Exception2 + { + }; + + class Base + { + public: + virtual ~Base() throw () {} + }; + + + class Bar : public Base + { + public: + virtual std::string ping() throw (Exception1, Exception2&) { return "Bar::ping()"; } + virtual std::string pong() throw (Unknown1, int, Unknown2&) { return "Bar::pong();" + ping(); } + virtual std::string pang() throw () { return "Bar::pang()"; } + }; + +%} |
