• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Standardized exception handling for UPM
2  *
3  * catch blocks should be listed in order from most specific to least
4  * specific.
5  */
6 
7 %include "exception.i"
8 
9 %exception {
10     try {
11       $action
catch(std::invalid_argument & e)12     } catch (std::invalid_argument& e) {
13       std::string s1("UPM Invalid Argument: "), s2(e.what());
14       s1 = s1 + s2;
15       SWIG_exception(SWIG_ValueError, s1.c_str());
16 
17     } catch (std::domain_error& e) {
18       std::string s1("UPM Domain Error: "), s2(e.what());
19       s1 = s1 + s2;
20       SWIG_exception(SWIG_ValueError, s1.c_str() );
21 
catch(std::overflow_error & e)22     } catch (std::overflow_error& e) {
23       std::string s1("UPM Overflow Error: "), s2(e.what());
24       s1 = s1 + s2;
25       SWIG_exception(SWIG_OverflowError, s1.c_str() );
26 
27     } catch (std::out_of_range& e) {
28       std::string s1("UPM Out of Range: "), s2(e.what());
29       s1 = s1 + s2;
30       SWIG_exception(SWIG_IndexError, s1.c_str() );
31 
catch(std::length_error & e)32     } catch (std::length_error& e) {
33       std::string s1("UPM Length Error: "), s2(e.what());
34       s1 = s1 + s2;
35       SWIG_exception(SWIG_IndexError, s1.c_str() );
36 
37     } catch (std::logic_error& e) {
38       std::string s1("UPM Logic Error: "), s2(e.what());
39       s1 = s1 + s2;
40       SWIG_exception(SWIG_RuntimeError, s1.c_str() );
41 
catch(std::bad_alloc & e)42     } catch (std::bad_alloc& e) {
43       /* for an allocation exception, don't try to create a string... */
44       SWIG_exception(SWIG_MemoryError, e.what() );
45 
46     } catch (std::runtime_error& e) {
47       /* catch other std::runtime_error exceptions here */
48       std::string s1("UPM Runtime Error: "), s2(e.what());
49       s1 = s1 + s2;
50       SWIG_exception(SWIG_RuntimeError, s1.c_str());
51 
catch(std::exception & e)52     } catch (std::exception& e) {
53       /* catch other std::exceptions here */
54       std::string s1("UPM Error: "), s2(e.what());
55       s1 = s1 + s2;
56       SWIG_exception(SWIG_SystemError, s1.c_str() );
57 
58     } catch (...) {
59       /* catch everything else */
60       SWIG_exception(SWIG_UnknownError, "UPM Unknown exception" );
61 
62     }
63 
64 }
65 
66