Merge pull request #793 from q-p/bad_cast

Add std::bad_cast to std_except.i
This commit is contained in:
William S Fulton 2016-09-25 14:12:01 +01:00 committed by GitHub
commit 5b8e8fa107
12 changed files with 24 additions and 0 deletions

View file

@ -7,6 +7,7 @@ public class li_std_except_runme {
public static void Main() {
Test test = new Test();
try { test.throw_bad_cast(); throw new Exception("throw_bad_cast failed"); } catch (InvalidCastException) {}
try { test.throw_bad_exception(); throw new Exception("throw_bad_exception failed"); } catch (ApplicationException) {}
try { test.throw_domain_error(); throw new Exception("throw_domain_error failed"); } catch (ApplicationException) {}
try { test.throw_exception(); throw new Exception("throw_exception failed"); } catch (ApplicationException) {}

View file

@ -24,6 +24,7 @@
int foo3() throw(E1) { return 0; }
int foo4() throw(E2) { return 0; }
// all the STL exceptions...
void throw_bad_cast() throw(std::bad_cast) { throw std::bad_cast(); }
void throw_bad_exception() throw(std::bad_exception) { throw std::bad_exception(); }
void throw_domain_error() throw(std::domain_error) { throw std::domain_error("oops"); }
void throw_exception() throw(std::exception) { throw std::exception(); }

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws, canthrow=1) std::bad_cast "SWIG_CSharpSetPendingException(SWIG_CSharpInvalidCastException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::bad_exception "SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::domain_error "SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::exception "SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, $1.what());\n return $null;"

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws, canthrow=1) std::bad_cast "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::bad_exception "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::domain_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
%typemap(throws, canthrow=1) std::exception "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"

View file

@ -258,6 +258,7 @@ SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
}
*/
%{
#include <typeinfo>
#include <stdexcept>
%}
%define SWIG_CATCH_STDEXCEPT
@ -274,6 +275,8 @@ SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
SWIG_exception(SWIG_IndexError, e.what() );
} catch (std::runtime_error& e) {
SWIG_exception(SWIG_RuntimeError, e.what() );
} catch (std::bad_cast& e) {
SWIG_exception(SWIG_TypeError, e.what() );
} catch (std::exception& e) {
SWIG_exception(SWIG_SystemError, e.what() );
}

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws) std::bad_cast %{_swig_gopanic($1.what());%}
%typemap(throws) std::bad_exception %{_swig_gopanic($1.what());%}
%typemap(throws) std::domain_error %{_swig_gopanic($1.what());%}
%typemap(throws) std::exception %{_swig_gopanic($1.what());%}

View file

@ -1,6 +1,7 @@
// TODO: STL exception handling
// Note that the generic std_except.i file did not work
%{
#include <typeinfo>
#include <stdexcept>
%}

View file

@ -7,6 +7,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -16,6 +17,7 @@ namespace std
struct exception {};
}
%typemap(throws) std::bad_cast "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"
%typemap(throws) std::bad_exception "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"
%typemap(throws) std::domain_error "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"
%typemap(throws) std::exception "SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1.what());\n return $null;"

View file

@ -8,6 +8,7 @@
* ----------------------------------------------------------------------------- */
%{
#include <typeinfo>
#include <stdexcept>
%}
%include <exception.i>
@ -27,6 +28,7 @@ namespace std
// normally objects which are thrown are returned to the interpreter as errors
// (which potentially may have problems if they are not copied)
// therefore all classes based upon std::exception are converted to their strings & returned as errors
%typemap(throws) std::bad_cast "SWIG_exception(SWIG_TypeError, $1.what());"
%typemap(throws) std::bad_exception "SWIG_exception(SWIG_RuntimeError, $1.what());"
%typemap(throws) std::domain_error "SWIG_exception(SWIG_ValueError, $1.what());"
%typemap(throws) std::exception "SWIG_exception(SWIG_SystemError, $1.what());"

View file

@ -3,6 +3,7 @@
#endif
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -15,6 +16,10 @@ namespace std {
virtual const char* what() const throw();
};
struct bad_cast : exception
{
};
struct bad_exception : exception
{
};

View file

@ -24,6 +24,7 @@
#endif
%{
#include <typeinfo>
#include <stdexcept>
%}
@ -40,6 +41,7 @@
%enddef
namespace std {
%std_exception_map(bad_cast, SWIG_TypeError);
%std_exception_map(bad_exception, SWIG_SystemError);
%std_exception_map(domain_error, SWIG_ValueError);
%std_exception_map(exception, SWIG_SystemError);

View file

@ -20,6 +20,7 @@
%enddef
namespace std {
%std_exception_map(bad_cast, SWIG_TypeError);
%std_exception_map(bad_exception, SWIG_SystemError);
%std_exception_map(domain_error, SWIG_ValueError);
%std_exception_map(exception, SWIG_SystemError);