scilab: document STL exceptions
This commit is contained in:
parent
ee139271d3
commit
eb62899fac
1 changed files with 15 additions and 10 deletions
|
|
@ -1256,31 +1256,36 @@ It can be used with the <tt>lasterror()</tt> function as following:
|
|||
</p>
|
||||
|
||||
<p>
|
||||
If the function has a <tt>throw</tt> exception speficication, SWIG can map automatically the exception type and set an appropriate Scilab error message.
|
||||
It works for exception basic types, like <tt>char*</tt> in the previous example or another example, <tt>int</tt>:
|
||||
If the function has a <tt>throw</tt> 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 <tt>std_except.i</tt> is used, also for STL exceptions:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
%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.");
|
||||
}
|
||||
%}
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
<div class="targetlang"><pre>
|
||||
-->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.
|
||||
</pre></div>
|
||||
</p>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue