Skip to content

Commit d79ca18

Browse files
Adding exception binding for Java and Python
1 parent bbfa4c9 commit d79ca18

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

src/AvTranscoder/avTranscoder.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
%include "std_pair.i"
66
%include "std_map.i"
77

8+
%include "exception.i"
9+
810
%{
911
#include <AvTranscoder/common.hpp>
1012

src/AvTranscoder/exception.i

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
%include <std_except.i>
2+
3+
/*
4+
All swig exception types:
5+
SWIG_MemoryError
6+
SWIG_IndexError
7+
SWIG_RuntimeError
8+
SWIG_IOError
9+
SWIG_TypeError
10+
SWIG_OverflowError
11+
SWIG_ValueError
12+
13+
SWIG_DivisionByZero
14+
SWIG_SyntaxError
15+
SWIG_SystemError
16+
*/
17+
18+
%exception {
19+
try
20+
{
21+
$action
22+
}
23+
catch( std::out_of_range& e )
24+
{
25+
SWIG_exception( SWIG_IndexError, e.what() );
26+
}
27+
catch( std::bad_alloc& e )
28+
{
29+
SWIG_exception( SWIG_MemoryError, e.what() );
30+
}
31+
catch( std::ios_base::failure& e )
32+
{
33+
SWIG_exception( SWIG_IOError, e.what() );
34+
}/*
35+
catch( std::bad_cast& e )
36+
{
37+
SWIG_exception( SWIG_TypeError, e.what() );
38+
}*/
39+
catch( std::overflow_error& e )
40+
{
41+
SWIG_exception( SWIG_OverflowError, e.what() );
42+
}
43+
catch( std::underflow_error& e )
44+
{
45+
SWIG_exception( SWIG_OverflowError, e.what() );
46+
}
47+
catch( std::invalid_argument& e )
48+
{
49+
SWIG_exception( SWIG_ValueError, e.what() );
50+
}
51+
catch( std::exception& e )
52+
{
53+
SWIG_exception( SWIG_RuntimeError, e.what() );
54+
}
55+
catch(...)
56+
{
57+
SWIG_exception( SWIG_RuntimeError, "Unknown C++ exception" );
58+
}
59+
60+
}

0 commit comments

Comments
 (0)