From eb62899fac2a853e344563e57a5f4308e7a4f6e9 Mon Sep 17 00:00:00 2001
From: Simon Marchetto
-If the function has a throw exception speficication, SWIG can map automatically the exception type and set an appropriate Scilab error message. -It works for exception basic types, like char* in the previous example or another example, int: +If the function has a throw exception specification, SWIG can map automatically the exception type and set an appropriate Scilab error message. +It works for exception basic types, and if the the library std_except.i is used, also for STL exceptions:
%module example
+%include <std_except.i>
+
%inline %{
void throw_int() throw(int) {
throw 12;
}
+
+void throw_stl_invalid_arg(int i) throw(std::invalid_argument) {
+ if (i < 0)
+ throw std::invalid_argument("argument is negative.");
+}
%}
--->execstr('throw_int()', 'errcatch');
- ans =
+-->throw_int();
+ !--error 999
+SWIG/Scilab: Exception (int) occured: 12
- 999.
-
--->lasterror()
- ans =
-
- Exception (int) occured: 12.
+-->throw_stl_invalid_arg(-1);
+ !--error 999
+SWIG/Scilab: ValueError: argument is negative.