From b250a711295f5ba00114f11a5b1c855eebe08d26 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 30 Aug 2012 11:41:15 +0300 Subject: [PATCH] Exception fixes Use out_of_range only when accessing arrays or array-like things, not for general numeric arguments. Armature::get_link functions now throw key_error since they behave like map access externally. --- source/animation.cpp | 3 ++- source/armature.cpp | 5 +++-- source/bloom.cpp | 4 ++-- source/buffer.cpp | 4 ++-- source/object.cpp | 4 ++-- source/pose.cpp | 2 +- source/texturecube.cpp | 2 +- source/texunit.cpp | 4 ++-- source/vertexformat.cpp | 2 +- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/source/animation.cpp b/source/animation.cpp index efb67c97..1aa8242a 100644 --- a/source/animation.cpp +++ b/source/animation.cpp @@ -3,6 +3,7 @@ #include #include "animation.h" #include "armature.h" +#include "error.h" #include "keyframe.h" #include "pose.h" @@ -206,7 +207,7 @@ Matrix Animation::Iterator::get_matrix() const Matrix Animation::Iterator::get_pose_matrix(unsigned link) const { if(!animation.armature) - throw logic_error("Animation::Iterator::get_pose_matrix"); + throw invalid_operation("Animation::Iterator::get_pose_matrix"); if(link>animation.armature->get_max_link_index()) throw out_of_range("Animation::Iterator::get_pose_matrix"); diff --git a/source/armature.cpp b/source/armature.cpp index d7a944ed..887d974a 100644 --- a/source/armature.cpp +++ b/source/armature.cpp @@ -1,3 +1,4 @@ +#include #include "armature.h" using namespace std; @@ -16,7 +17,7 @@ const Armature::Link &Armature::get_link(unsigned index) const for(list::const_iterator i=links.begin(); i!=links.end(); ++i) if(i->get_index()==index) return *i; - throw invalid_argument("Armature::get_link"); + throw key_error(typeid(list)); } const Armature::Link &Armature::get_link(const string &name) const @@ -24,7 +25,7 @@ const Armature::Link &Armature::get_link(const string &name) const for(list::const_iterator i=links.begin(); i!=links.end(); ++i) if(i->get_name()==name) return *i; - throw invalid_argument("Armature::get_link"); + throw key_error(typeid(list)); } unsigned Armature::get_max_link_index() const diff --git a/source/bloom.cpp b/source/bloom.cpp index b73ea160..8fda424d 100644 --- a/source/bloom.cpp +++ b/source/bloom.cpp @@ -72,7 +72,7 @@ Bloom::Bloom(unsigned w, unsigned h): void Bloom::set_radius(float r) { if(r<=0.0f) - throw out_of_range("Bloom::set_radius"); + throw invalid_argument("Bloom::set_radius"); int size = min(static_cast(r*3.0f), 9); blur_shdata_common.uniform("size", size); @@ -91,7 +91,7 @@ void Bloom::set_radius(float r) void Bloom::set_strength(float s) { if(s<0.0f || s>1.0f) - throw out_of_range("Bloom::set_strength"); + throw invalid_argument("Bloom::set_strength"); combine_shdata.uniform("strength", s); } diff --git a/source/buffer.cpp b/source/buffer.cpp index 84c72716..5a0f4762 100644 --- a/source/buffer.cpp +++ b/source/buffer.cpp @@ -151,13 +151,13 @@ const BufferRange *&BufferRange::binding(BufferType type, unsigned index) if(type==UNIFORM_BUFFER) { if(index>=get_n_uniform_buffer_bindings()) - throw out_of_range("Buffer::binding"); + throw out_of_range("BufferRange::binding"); if(bound_uniform.size()<=index) bound_uniform.resize(index+1); return bound_uniform[index]; } else - throw invalid_argument("Buffer::binding"); + throw invalid_argument("BufferRange::binding"); } bool BufferRange::set_current(BufferType type, unsigned index, const BufferRange *buf) diff --git a/source/object.cpp b/source/object.cpp index 964099e5..bd899961 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -32,7 +32,7 @@ Object::~Object() void Object::set_mesh(unsigned i, const Mesh *m) { if(i>meshes.size()) - throw invalid_argument("Object::set_mesh"); + throw out_of_range("Object::set_mesh"); if(i==meshes.size()) meshes.push_back(m); @@ -144,7 +144,7 @@ void Object::Loader::mesh_inline() void Object::Loader::mesh_inline_lod(unsigned l) { if(l>obj.meshes.size()) - throw invalid_argument("Object::Loader::mesh_inline_lod"); + throw out_of_range("Object::Loader::mesh_inline_lod"); RefPtr msh = new Mesh; load_sub(*msh); diff --git a/source/pose.cpp b/source/pose.cpp index 4d589397..63346b08 100644 --- a/source/pose.cpp +++ b/source/pose.cpp @@ -68,7 +68,7 @@ void Pose::Loader::armature(const string &n) void Pose::Loader::link(const string &n) { if(!obj.armature) - error("Armature must be specified first"); + throw logic_error("Armature must be specified first"); LinkLoader ldr(obj, obj.armature->get_link(n).get_index()); load_sub_with(ldr); } diff --git a/source/texturecube.cpp b/source/texturecube.cpp index a5874a6a..6935e582 100644 --- a/source/texturecube.cpp +++ b/source/texturecube.cpp @@ -54,7 +54,7 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D unsigned s = get_level_size(level); if(s==0) - throw invalid_argument("TextureCube::image"); + throw out_of_range("TextureCube::image"); Bind _bind(this, true); glTexImage2D(face, level, ifmt, s, s, 0, fmt, type, data); diff --git a/source/texunit.cpp b/source/texunit.cpp index b19e7917..0a5f9bf3 100644 --- a/source/texunit.cpp +++ b/source/texunit.cpp @@ -36,7 +36,7 @@ bool TexUnit::set_texenv(const TexEnv *env) bool TexUnit::set_texgen(unsigned i, const TexGen *gen) { if(i>=4) - throw invalid_argument("TexUnit::set_texgen"); + throw out_of_range("TexUnit::set_texgen"); bool result = (texgen[i]!=gen); texgen[i] = gen; return result; @@ -45,7 +45,7 @@ bool TexUnit::set_texgen(unsigned i, const TexGen *gen) const TexGen *TexUnit::get_texgen(unsigned i) { if(i>=4) - throw invalid_argument("TexUnit::get_texgen"); + throw out_of_range("TexUnit::get_texgen"); return texgen[i]; } diff --git a/source/vertexformat.cpp b/source/vertexformat.cpp index ed2b04b8..e3f8bf97 100644 --- a/source/vertexformat.cpp +++ b/source/vertexformat.cpp @@ -114,7 +114,7 @@ VertexFormat operator,(const VertexFormat &f, unsigned i) VertexFormat r = f; unsigned char *c = r.data+r.data[0]; if((*c0) || (*c=8) || i>=53) - throw out_of_range("VertexFormat::operator,"); + throw invalid_argument("VertexFormat::operator,"); *c += i*4; return r; -- 2.43.0