Java std::vector std::list: add missing exception handling

This commit is contained in:
William S Fulton 2017-06-24 22:53:11 +01:00
commit a8e948e96d
2 changed files with 6 additions and 6 deletions

View file

@ -177,13 +177,13 @@ namespace std {
%extend { %extend {
%fragment("SWIG_ListSize"); %fragment("SWIG_ListSize");
list(jint count) { list(jint count) throw (std::out_of_range) {
if (count < 0) if (count < 0)
throw std::out_of_range("list count must be positive"); throw std::out_of_range("list count must be positive");
return new std::list<T>(static_cast<std::list<T>::size_type>(count)); return new std::list<T>(static_cast<std::list<T>::size_type>(count));
} }
list(jint count, const T &value) { list(jint count, const T &value) throw (std::out_of_range) {
if (count < 0) if (count < 0)
throw std::out_of_range("list count must be positive"); throw std::out_of_range("list count must be positive");
return new std::list<T>(static_cast<std::list<T>::size_type>(count), value); return new std::list<T>(static_cast<std::list<T>::size_type>(count), value);
@ -193,11 +193,11 @@ namespace std {
return SWIG_ListSize(self->size()); return SWIG_ListSize(self->size());
} }
jint doPreviousIndex(const iterator &pos) const { jint doPreviousIndex(const iterator &pos) const throw (std::out_of_range) {
return pos == self->begin() ? -1 : SWIG_ListSize(std::distance(self->begin(), static_cast<std::list<T>::const_iterator>(pos))); return pos == self->begin() ? -1 : SWIG_ListSize(std::distance(self->begin(), static_cast<std::list<T>::const_iterator>(pos)));
} }
jint doNextIndex(const iterator &pos) const { jint doNextIndex(const iterator &pos) const throw (std::out_of_range) {
return pos == self->end() ? self->size() : SWIG_ListSize(std::distance(self->begin(), static_cast<std::list<T>::const_iterator>(pos))); return pos == self->end() ? self->size() : SWIG_ListSize(std::distance(self->begin(), static_cast<std::list<T>::const_iterator>(pos)));
} }

View file

@ -83,13 +83,13 @@ SWIGINTERN jint SWIG_VectorSize(size_t size) {
void clear(); void clear();
%extend { %extend {
%fragment("SWIG_VectorSize"); %fragment("SWIG_VectorSize");
vector(jint count) { vector(jint count) throw (std::out_of_range) {
if (count < 0) if (count < 0)
throw std::out_of_range("vector count must be positive"); throw std::out_of_range("vector count must be positive");
return new std::vector< CTYPE >(static_cast<std::vector< CTYPE >::size_type>(count)); return new std::vector< CTYPE >(static_cast<std::vector< CTYPE >::size_type>(count));
} }
vector(jint count, const CTYPE &value) { vector(jint count, const CTYPE &value) throw (std::out_of_range) {
if (count < 0) if (count < 0)
throw std::out_of_range("vector count must be positive"); throw std::out_of_range("vector count must be positive");
return new std::vector< CTYPE >(static_cast<std::vector< CTYPE >::size_type>(count), value); return new std::vector< CTYPE >(static_cast<std::vector< CTYPE >::size_type>(count), value);