mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00

This commit moves common SWIG syntax to a ${libname}.i for sensor libraries. Much of the swig content was originally duplicated for each wrapper language which has lead to inconsistencies between wrappers over time. This commit moves all swig syntax to a common file. Language specific swig syntax can be added with #ifdef SWIG<LANGUAGE>. The src/CMakeLists.txt will look first for a language-specific .i file, then fall back to ${libname}.i. In this way, it's possible to override the common ${libname}.i file. If a fallback .i file does NOT exist, UPM CMake will generate a simple interface file for all languages. Example: If no src/abp/pyupm_abp.i and no src/abp/abp.i then generate ${CMAKE_CURRENT_BINARY_DIR}/abp.i When src/CMakeLists.txt uses a common ${libname}.i, it adds a -module <language>upm_${libname} to the swig command line. In the example below, a -module argument is provided for both Java and Javascript, while the python module takes all syntax from pyupm_abp.i. SWIG FILE Language CMake added SWIG args --------------- ---------- --------------------- src/abp/abp.i java -module javaupm_abp src/abp/abp.i javascript -module jsupm_abp src/abp/pyupm_abp.i python This commit removes ~4500 redundant lines for the UPM repository and helps promote uniformity for the SWIG'ed languages. Signed-off-by: Noel Eck <noel.eck@intel.com>
64 lines
1.8 KiB
OpenEdge ABL
64 lines
1.8 KiB
OpenEdge ABL
/* Standardized exception handling for UPM
|
|
*
|
|
* catch blocks should be listed in order from most specific to least
|
|
* specific.
|
|
*/
|
|
|
|
%{#include <stdexcept>%}
|
|
%include "exception.i"
|
|
|
|
%exception {
|
|
try {
|
|
$action
|
|
} catch (std::invalid_argument& e) {
|
|
std::string s1("UPM Invalid Argument: "), s2(e.what());
|
|
s1 = s1 + s2;
|
|
SWIG_exception(SWIG_ValueError, s1.c_str());
|
|
|
|
} catch (std::domain_error& e) {
|
|
std::string s1("UPM Domain Error: "), s2(e.what());
|
|
s1 = s1 + s2;
|
|
SWIG_exception(SWIG_ValueError, s1.c_str() );
|
|
|
|
} catch (std::overflow_error& e) {
|
|
std::string s1("UPM Overflow Error: "), s2(e.what());
|
|
s1 = s1 + s2;
|
|
SWIG_exception(SWIG_OverflowError, s1.c_str() );
|
|
|
|
} catch (std::out_of_range& e) {
|
|
std::string s1("UPM Out of Range: "), s2(e.what());
|
|
s1 = s1 + s2;
|
|
SWIG_exception(SWIG_IndexError, s1.c_str() );
|
|
|
|
} catch (std::length_error& e) {
|
|
std::string s1("UPM Length Error: "), s2(e.what());
|
|
s1 = s1 + s2;
|
|
SWIG_exception(SWIG_IndexError, s1.c_str() );
|
|
|
|
} catch (std::logic_error& e) {
|
|
std::string s1("UPM Logic Error: "), s2(e.what());
|
|
s1 = s1 + s2;
|
|
SWIG_exception(SWIG_RuntimeError, s1.c_str() );
|
|
|
|
} catch (std::bad_alloc& e) {
|
|
/* for an allocation exception, don't try to create a string... */
|
|
SWIG_exception(SWIG_MemoryError, e.what() );
|
|
|
|
} catch (std::runtime_error& e) {
|
|
/* catch other std::runtime_error exceptions here */
|
|
std::string s1("UPM Runtime Error: "), s2(e.what());
|
|
s1 = s1 + s2;
|
|
SWIG_exception(SWIG_RuntimeError, s1.c_str());
|
|
|
|
} catch (std::exception& e) {
|
|
/* catch other std::exceptions here */
|
|
std::string s1("UPM Error: "), s2(e.what());
|
|
s1 = s1 + s2;
|
|
SWIG_exception(SWIG_SystemError, s1.c_str() );
|
|
|
|
} catch (...) {
|
|
/* catch everything else */
|
|
SWIG_exception(SWIG_UnknownError, "UPM Unknown exception" );
|
|
}
|
|
}
|