use exception specification instead of %exception to handle STL error checking

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7352 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2005-07-27 20:09:42 +00:00
commit 49639577e0
34 changed files with 299 additions and 849 deletions

View file

@ -5,5 +5,7 @@
//
// Java implementation
%include <std/std_except.i>
%apply size_t { std::size_t };

View file

@ -5,26 +5,7 @@
//
// Common implementation
%include std_common.i
%include exception.i
%exception std::map::get {
try {
$action
} catch (std::out_of_range& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
return $null;
}
}
%exception std::map::del {
try {
$action
} catch (std::out_of_range& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
return $null;
}
}
%include <std_common.i>
// ------------------------------------------------------------------------
// std::map
@ -50,7 +31,7 @@ namespace std {
bool empty() const;
void clear();
%extend {
T& get(const K& key) {
T& get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
@ -60,7 +41,7 @@ namespace std {
void set(const K& key, const T& x) {
(*self)[key] = x;
}
void del(const K& key) {
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
@ -89,7 +70,7 @@ namespace std {
bool empty() const;
void clear();
%extend {
T& get(K key) {
T& get(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
@ -99,7 +80,7 @@ namespace std {
void set(K key, const T& x) {
(*self)[key] = x;
}
void del(K key) {
void del(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
@ -125,7 +106,7 @@ namespace std {
bool empty() const;
void clear();
%extend {
T get(const K& key) {
T get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
@ -135,7 +116,7 @@ namespace std {
void set(const K& key, T x) {
(*self)[key] = x;
}
void del(const K& key) {
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
@ -162,7 +143,7 @@ namespace std {
bool empty() const;
void clear();
%extend {
T get(K key) {
T get(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
@ -172,7 +153,7 @@ namespace std {
void set(K key, T x) {
(*self)[key] = x;
}
void del(K key) {
void del(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);

View file

@ -5,27 +5,7 @@
//
// Java implementation
%include exception.i
%exception std::vector::get {
try {
$action
} catch (std::out_of_range& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
return $null;
}
}
%exception std::vector::set {
try {
$action
} catch (std::out_of_range& e) {
SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
return $null;
}
}
%include <std_common.i>
// ------------------------------------------------------------------------
// std::vector
@ -73,14 +53,14 @@ namespace std {
%rename(add) push_back;
void push_back(const T& x);
%extend {
T& get(int i) {
T& get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const T& x) {
void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;
@ -106,14 +86,14 @@ namespace std {
%rename(add) push_back;
void push_back(T x);
%extend {
T get(int i) {
T get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, T x) {
void set(int i, T x) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;