diff --git a/Examples/javascript/exception/example.h b/Examples/javascript/exception/example.h index 1658ec770..bc744cda7 100644 --- a/Examples/javascript/exception/example.h +++ b/Examples/javascript/exception/example.h @@ -16,34 +16,26 @@ public: char msg[256]; }; -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif - class Test { public: - int simple() throw(int) { + int simple() { throw(37); return 1; } - int message() throw(const char *) { + int message() { throw("I died."); return 1; } - int hosed() throw(Exc) { + int hosed() { throw(Exc(42,"Hosed")); return 1; } - int unknown() throw(A*) { + int unknown() { static A a; throw &a; return 1; } - int multi(int x) throw(int, const char *, Exc) { + int multi(int x) { if (x == 1) throw(37); if (x == 2) throw("Bleah!"); if (x == 3) throw(Exc(42,"No-go-diggy-die")); @@ -51,10 +43,3 @@ public: } }; -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif - diff --git a/Examples/javascript/exception/example.i b/Examples/javascript/exception/example.i index 08672c3a8..ca1084452 100644 --- a/Examples/javascript/exception/example.i +++ b/Examples/javascript/exception/example.i @@ -7,6 +7,12 @@ %include "std_string.i" +%catches(int) Test::simple(); +%catches(const char *) Test::message(); +%catches(Exc) Test::hosed(); +%catches(A*) Test::unknown(); +%catches(int, const char *, Exc) Test::multi(int x); + /* Let's just grab the original header file here */ %include "example.h" diff --git a/Examples/lua/exception/example.h b/Examples/lua/exception/example.h index ea3b4fc63..bc744cda7 100644 --- a/Examples/lua/exception/example.h +++ b/Examples/lua/exception/example.h @@ -1,6 +1,6 @@ /* File : example.h */ -#include +#include #ifndef SWIG struct A { }; @@ -16,34 +16,26 @@ public: char msg[256]; }; -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif - class Test { public: - int simple() throw(int) { + int simple() { throw(37); return 1; } - int message() throw(const char *) { + int message() { throw("I died."); return 1; } - int hosed() throw(Exc) { + int hosed() { throw(Exc(42,"Hosed")); return 1; } - int unknown() throw(A*) { + int unknown() { static A a; throw &a; return 1; } - int multi(int x) throw(int, const char *, Exc) { + int multi(int x) { if (x == 1) throw(37); if (x == 2) throw("Bleah!"); if (x == 3) throw(Exc(42,"No-go-diggy-die")); @@ -51,10 +43,3 @@ public: } }; -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif - diff --git a/Examples/lua/exception/example.i b/Examples/lua/exception/example.i index 6187f8eff..a6b43837d 100644 --- a/Examples/lua/exception/example.i +++ b/Examples/lua/exception/example.i @@ -12,6 +12,12 @@ // note: only works if Exc is copyable %apply SWIGTYPE EXCEPTION_BY_VAL {Exc}; +%catches(int) Test::simple(); +%catches(const char *) Test::message(); +%catches(Exc) Test::hosed(); +%catches(A*) Test::unknown(); +%catches(int, const char *, Exc) Test::multi(int x); + /* Let's just grab the original header file here */ %include "example.h" diff --git a/Examples/python/exception/example.h b/Examples/python/exception/example.h index ea3b4fc63..bc744cda7 100644 --- a/Examples/python/exception/example.h +++ b/Examples/python/exception/example.h @@ -1,6 +1,6 @@ /* File : example.h */ -#include +#include #ifndef SWIG struct A { }; @@ -16,34 +16,26 @@ public: char msg[256]; }; -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif - class Test { public: - int simple() throw(int) { + int simple() { throw(37); return 1; } - int message() throw(const char *) { + int message() { throw("I died."); return 1; } - int hosed() throw(Exc) { + int hosed() { throw(Exc(42,"Hosed")); return 1; } - int unknown() throw(A*) { + int unknown() { static A a; throw &a; return 1; } - int multi(int x) throw(int, const char *, Exc) { + int multi(int x) { if (x == 1) throw(37); if (x == 2) throw("Bleah!"); if (x == 3) throw(Exc(42,"No-go-diggy-die")); @@ -51,10 +43,3 @@ public: } }; -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif - diff --git a/Examples/python/exception/example.i b/Examples/python/exception/example.i index 817c5221c..3a3a6548f 100644 --- a/Examples/python/exception/example.i +++ b/Examples/python/exception/example.i @@ -7,6 +7,12 @@ %include "std_string.i" +%catches(int) Test::simple(); +%catches(const char *) Test::message(); +%catches(Exc) Test::hosed(); +%catches(A*) Test::unknown(); +%catches(int, const char *, Exc) Test::multi(int x); + /* Let's just grab the original header file here */ %include "example.h" diff --git a/Examples/python/exceptproxy/example.h b/Examples/python/exceptproxy/example.h index 0c03873fc..3ee6d765d 100644 --- a/Examples/python/exceptproxy/example.h +++ b/Examples/python/exceptproxy/example.h @@ -8,14 +8,6 @@ class FullError { FullError(int m) : maxsize(m) { } }; -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif - template class Queue { int maxsize; T *items; @@ -31,7 +23,7 @@ template class Queue { ~Queue() { delete [] items; } - void enqueue(T x) throw(FullError) { + void enqueue(T x) { if (nitems == maxsize) { throw FullError(maxsize); } @@ -51,11 +43,3 @@ template class Queue { } }; - -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif - diff --git a/Examples/python/exceptproxy/example.i b/Examples/python/exceptproxy/example.i index 0a46afbb6..f5f835149 100644 --- a/Examples/python/exceptproxy/example.i +++ b/Examples/python/exceptproxy/example.i @@ -20,29 +20,12 @@ the header file, the enqueue method throws FullError and the dequeue method throws EmptyError. Since we don't want to define an exception handler for everything, we - simply write a handler each method individually. + simply write a handler for each method individually. Note: the *::enqueue syntax means that we simply define the handler for any class with this method defined. */ -/* - First we need to 'disable' the default swig throw mechanism for the - FullError class. We do this by rethrowing the exception. - - Note that this is necessary since the class appears in a throw - declaration: - - - void enqueue(T x) throw(FullError); - - hence, swig recognizes it as an exception class and it will generate - the necessary code to catch it and rethrow it to the python side. - -*/ -%typemap(throws) FullError "(void)$1; throw;"; - - %exception *::enqueue { try { $action @@ -76,7 +59,7 @@ */ /* - Now, the EmpytError doesn't appear in a throw declaration, and hence + Now, the EmptyError doesn't appear in a throw declaration, and hence we need to 'mark' it as an exception class. In python, classes that are used as exception are 'special', and need to be wrapped as 'classic' ones. diff --git a/Examples/ruby/exceptproxy/example.h b/Examples/ruby/exceptproxy/example.h index c29a562db..3ee6d765d 100644 --- a/Examples/ruby/exceptproxy/example.h +++ b/Examples/ruby/exceptproxy/example.h @@ -8,14 +8,6 @@ class FullError { FullError(int m) : maxsize(m) { } }; -#if defined(_MSC_VER) - #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdeprecated" // dynamic exception specifications are deprecated in C++11 -#endif - template class Queue { int maxsize; T *items; @@ -31,7 +23,7 @@ template class Queue { ~Queue() { delete [] items; } - void enqueue(T x) throw(FullError) { + void enqueue(T x) { if (nitems == maxsize) { throw FullError(maxsize); } @@ -51,15 +43,3 @@ template class Queue { } }; - -#if defined(_MSC_VER) - #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) -#endif -#if __GNUC__ >= 7 - #pragma GCC diagnostic pop -#endif - - - - - diff --git a/Examples/ruby/exceptproxy/example.i b/Examples/ruby/exceptproxy/example.i index 5094b7a60..8e00751b2 100644 --- a/Examples/ruby/exceptproxy/example.i +++ b/Examples/ruby/exceptproxy/example.i @@ -17,6 +17,7 @@ /* The EmpytError doesn't appear in a throw declaration, and hence we need to tell SWIG that the dequeue method throws it. This can now be done via the %catchs feature. */ +%catches(FullError) *::enqueue; %catches(EmptyError) *::dequeue();