use specialized exception classes

This commit is contained in:
wmayer
2017-04-28 18:49:11 +02:00
parent 998c000516
commit fb7094bf31
60 changed files with 675 additions and 349 deletions

View File

@@ -56,7 +56,7 @@ ImageBase::ImageBase(const ImageBase &rhs)
_pPixelData = NULL;
_owner = false; // avoids a superfluous delete
if (createCopy((void *)(rhs._pPixelData), rhs._width, rhs._height, rhs._format, rhs._numSigBitsPerSample) != 0)
throw Base::Exception("ImageBase::ImageBase. Error creating copy of image");
throw Base::RuntimeError("ImageBase::ImageBase. Error creating copy of image");
}
else
{
@@ -84,7 +84,7 @@ ImageBase & ImageBase::operator=(const ImageBase &rhs)
// rhs is the owner - do a deep copy
_owner = false; // avoids a superfluous delete
if (createCopy((void *)(rhs._pPixelData), rhs._width, rhs._height, rhs._format, rhs._numSigBitsPerSample) != 0)
throw Base::Exception("ImageBase::operator=. Error creating copy of image");
throw Base::RuntimeError("ImageBase::operator=. Error creating copy of image");
}
else
{

View File

@@ -904,7 +904,7 @@ void MeshKernel::Read (std::istream &rclIn)
}
catch (std::exception&) {
// Special handling of std::length_error
throw Base::Exception("Reading from stream failed");
throw Base::BadFormatError("Reading from stream failed");
}
}
else {

View File

@@ -93,7 +93,7 @@ Base::Matrix4D AbstractPolygonTriangulator::GetTransformToFitPlane() const
planeFit.AddPoint(*it);
if (planeFit.Fit() == FLOAT_MAX)
throw Base::Exception("Plane fit failed");
throw Base::RuntimeError("Plane fit failed");
Base::Vector3f bs = planeFit.GetBase();
Base::Vector3f ex = planeFit.GetDirU();

View File

@@ -91,7 +91,7 @@ App::DocumentObjectExecReturn *SetOperations::execute(void)
else if (ot == "outer")
type = MeshCore::SetOperations::Outer;
else
throw new Base::Exception("Operation type must either be 'union' or 'intersection'"
throw new Base::ValueError("Operation type must either be 'union' or 'intersection'"
" or 'difference' or 'inner' or 'outer'");
MeshCore::SetOperations setOp(meshKernel1.getKernel(), meshKernel2.getKernel(),
@@ -102,9 +102,9 @@ App::DocumentObjectExecReturn *SetOperations::execute(void)
else {
// Error mesh property
if (!mesh1)
throw new Base::Exception("First input mesh not set");
throw new Base::ValueError("First input mesh not set");
if (!mesh2)
throw new Base::Exception("Second input mesh not set");
throw new Base::ValueError("Second input mesh not set");
}
return App::DocumentObject::StdReturn;

View File

@@ -1654,7 +1654,7 @@ void MeshObject::addSegment(const std::vector<unsigned long>& inds)
unsigned long maxIndex = _kernel.CountFacets();
for (std::vector<unsigned long>::const_iterator it = inds.begin(); it != inds.end(); ++it) {
if (*it >= maxIndex)
throw Base::Exception("Index out of range");
throw Base::IndexError("Index out of range");
}
this->_segments.push_back(Segment(this,inds,true));

View File

@@ -61,7 +61,7 @@ void PointsAlgos::Load(PointKernel &points, const char *FileName)
if (File.extension() == "asc" ||File.extension() == "ASC")
LoadAscii(points,FileName);
else
throw Base::Exception("Unknown ending");
throw Base::RuntimeError("Unknown ending");
}
void PointsAlgos::LoadAscii(PointKernel &points, const char *FileName)
@@ -109,7 +109,7 @@ void PointsAlgos::LoadAscii(PointKernel &points, const char *FileName)
}
catch (...) {
points.clear();
throw Base::Exception("Reading in points failed.");
throw Base::BadFormatError("Reading in points failed.");
}
// now remove the last points from the kernel
@@ -228,36 +228,36 @@ void PlyReader::read(const std::string& filename)
Eigen::Vector4f origin;
Eigen::Quaternionf orientation;
int ply_version;
int data_type;
unsigned int data_idx;
pcl::PLYReader ply;
ply.readHeader(filename, cloud2, origin, orientation, ply_version, data_type, data_idx);
bool hasIntensity = false;
bool hasColors = false;
bool hasNormals = false;
for (size_t i = 0; i < cloud2.fields.size (); ++i) {
if (cloud2.fields[i].name == "intensity")
hasIntensity = true;
if (cloud2.fields[i].name == "normal_x" || cloud2.fields[i].name == "nx")
hasNormals = true;
if (cloud2.fields[i].name == "normal_y" || cloud2.fields[i].name == "ny")
hasNormals = true;
if (cloud2.fields[i].name == "normal_z" || cloud2.fields[i].name == "nz")
hasNormals = true;
if (cloud2.fields[i].name == "red")
hasColors = true;
if (cloud2.fields[i].name == "green")
hasColors = true;
if (cloud2.fields[i].name == "blue")
hasColors = true;
if (cloud2.fields[i].name == "rgb")
hasColors = true;
if (cloud2.fields[i].name == "rgba")
hasColors = true;
}
if (hasNormals && hasColors) {
int data_type;
unsigned int data_idx;
pcl::PLYReader ply;
ply.readHeader(filename, cloud2, origin, orientation, ply_version, data_type, data_idx);
bool hasIntensity = false;
bool hasColors = false;
bool hasNormals = false;
for (size_t i = 0; i < cloud2.fields.size (); ++i) {
if (cloud2.fields[i].name == "intensity")
hasIntensity = true;
if (cloud2.fields[i].name == "normal_x" || cloud2.fields[i].name == "nx")
hasNormals = true;
if (cloud2.fields[i].name == "normal_y" || cloud2.fields[i].name == "ny")
hasNormals = true;
if (cloud2.fields[i].name == "normal_z" || cloud2.fields[i].name == "nz")
hasNormals = true;
if (cloud2.fields[i].name == "red")
hasColors = true;
if (cloud2.fields[i].name == "green")
hasColors = true;
if (cloud2.fields[i].name == "blue")
hasColors = true;
if (cloud2.fields[i].name == "rgb")
hasColors = true;
if (cloud2.fields[i].name == "rgba")
hasColors = true;
}
if (hasNormals && hasColors) {
pcl::PointCloud<pcl::PointXYZRGBNormal> cloud_in;
pcl::io::loadPLYFile<pcl::PointXYZRGBNormal>(filename, cloud_in);
points.reserve(cloud_in.size());
@@ -268,8 +268,8 @@ void PlyReader::read(const std::string& filename)
colors.push_back(App::Color(it->r/255.0f,it->g/255.0f,it->b/255.0f));
normals.push_back(Base::Vector3f(it->normal_x,it->normal_y,it->normal_z));
}
}
else if (hasNormals && hasIntensity) {
}
else if (hasNormals && hasIntensity) {
pcl::PointCloud<pcl::PointXYZINormal> cloud_in;
pcl::io::loadPLYFile<pcl::PointXYZINormal>(filename, cloud_in);
points.reserve(cloud_in.size());
@@ -280,8 +280,8 @@ void PlyReader::read(const std::string& filename)
intensity.push_back(it->intensity);
normals.push_back(Base::Vector3f(it->normal_x,it->normal_y,it->normal_z));
}
}
else if (hasColors) {
}
else if (hasColors) {
pcl::PointCloud<pcl::PointXYZRGBA> cloud_in;
pcl::io::loadPLYFile<pcl::PointXYZRGBA>(filename, cloud_in);
points.reserve(cloud_in.size());
@@ -290,8 +290,8 @@ void PlyReader::read(const std::string& filename)
points.push_back(Base::Vector3d(it->x,it->y,it->z));
colors.push_back(App::Color(it->r/255.0f,it->g/255.0f,it->b/255.0f,it->a/255.0f));
}
}
else if (hasIntensity) {
}
else if (hasIntensity) {
pcl::PointCloud<pcl::PointXYZI> cloud_in;
pcl::io::loadPLYFile<pcl::PointXYZI>(filename, cloud_in);
points.reserve(cloud_in.size());
@@ -300,8 +300,8 @@ void PlyReader::read(const std::string& filename)
points.push_back(Base::Vector3d(it->x,it->y,it->z));
intensity.push_back(it->intensity);
}
}
else if (hasNormals) {
}
else if (hasNormals) {
pcl::PointCloud<pcl::PointNormal> cloud_in;
pcl::io::loadPLYFile<pcl::PointNormal>(filename, cloud_in);
points.reserve(cloud_in.size());
@@ -310,15 +310,15 @@ void PlyReader::read(const std::string& filename)
points.push_back(Base::Vector3d(it->x,it->y,it->z));
normals.push_back(Base::Vector3f(it->normal_x,it->normal_y,it->normal_z));
}
}
else {
}
else {
pcl::PointCloud<pcl::PointXYZ> cloud_in;
pcl::io::loadPLYFile<pcl::PointXYZ>(filename, cloud_in);
points.reserve(cloud_in.size());
for (pcl::PointCloud<pcl::PointXYZ>::const_iterator it = cloud_in.begin();it!=cloud_in.end();++it) {
points.push_back(Base::Vector3d(it->x,it->y,it->z));
}
}
}
}
// ----------------------------------------------------------------------------
@@ -340,39 +340,39 @@ void PcdReader::read(const std::string& filename)
Eigen::Vector4f origin;
Eigen::Quaternionf orientation;
int ply_version;
int data_type;
unsigned int data_idx;
pcl::PCDReader pcd;
pcd.readHeader(filename, cloud2, origin, orientation, ply_version, data_type, data_idx);
bool hasIntensity = false;
bool hasColors = false;
bool hasNormals = false;
for (size_t i = 0; i < cloud2.fields.size (); ++i) {
if (cloud2.fields[i].name == "intensity")
hasIntensity = true;
if (cloud2.fields[i].name == "normal_x" || cloud2.fields[i].name == "nx")
hasNormals = true;
if (cloud2.fields[i].name == "normal_y" || cloud2.fields[i].name == "ny")
hasNormals = true;
if (cloud2.fields[i].name == "normal_z" || cloud2.fields[i].name == "nz")
hasNormals = true;
if (cloud2.fields[i].name == "red")
hasColors = true;
if (cloud2.fields[i].name == "green")
hasColors = true;
if (cloud2.fields[i].name == "blue")
hasColors = true;
if (cloud2.fields[i].name == "rgb")
hasColors = true;
if (cloud2.fields[i].name == "rgba")
hasColors = true;
}
width = cloud2.width;
height = cloud2.height;
if (hasNormals && hasColors) {
int data_type;
unsigned int data_idx;
pcl::PCDReader pcd;
pcd.readHeader(filename, cloud2, origin, orientation, ply_version, data_type, data_idx);
bool hasIntensity = false;
bool hasColors = false;
bool hasNormals = false;
for (size_t i = 0; i < cloud2.fields.size (); ++i) {
if (cloud2.fields[i].name == "intensity")
hasIntensity = true;
if (cloud2.fields[i].name == "normal_x" || cloud2.fields[i].name == "nx")
hasNormals = true;
if (cloud2.fields[i].name == "normal_y" || cloud2.fields[i].name == "ny")
hasNormals = true;
if (cloud2.fields[i].name == "normal_z" || cloud2.fields[i].name == "nz")
hasNormals = true;
if (cloud2.fields[i].name == "red")
hasColors = true;
if (cloud2.fields[i].name == "green")
hasColors = true;
if (cloud2.fields[i].name == "blue")
hasColors = true;
if (cloud2.fields[i].name == "rgb")
hasColors = true;
if (cloud2.fields[i].name == "rgba")
hasColors = true;
}
width = cloud2.width;
height = cloud2.height;
if (hasNormals && hasColors) {
pcl::PointCloud<pcl::PointXYZRGBNormal> cloud_in;
pcl::io::loadPCDFile<pcl::PointXYZRGBNormal>(filename, cloud_in);
points.reserve(cloud_in.size());
@@ -383,8 +383,8 @@ void PcdReader::read(const std::string& filename)
colors.push_back(App::Color(it->r/255.0f,it->g/255.0f,it->b/255.0f));
normals.push_back(Base::Vector3f(it->normal_x,it->normal_y,it->normal_z));
}
}
else if (hasNormals && hasIntensity) {
}
else if (hasNormals && hasIntensity) {
pcl::PointCloud<pcl::PointXYZINormal> cloud_in;
pcl::io::loadPCDFile<pcl::PointXYZINormal>(filename, cloud_in);
points.reserve(cloud_in.size());
@@ -395,8 +395,8 @@ void PcdReader::read(const std::string& filename)
intensity.push_back(it->intensity);
normals.push_back(Base::Vector3f(it->normal_x,it->normal_y,it->normal_z));
}
}
else if (hasColors) {
}
else if (hasColors) {
pcl::PointCloud<pcl::PointXYZRGBA> cloud_in;
pcl::io::loadPCDFile<pcl::PointXYZRGBA>(filename, cloud_in);
points.reserve(cloud_in.size());
@@ -405,8 +405,8 @@ void PcdReader::read(const std::string& filename)
points.push_back(Base::Vector3d(it->x,it->y,it->z));
colors.push_back(App::Color(it->r/255.0f,it->g/255.0f,it->b/255.0f,it->a/255.0f));
}
}
else if (hasIntensity) {
}
else if (hasIntensity) {
pcl::PointCloud<pcl::PointXYZI> cloud_in;
pcl::io::loadPCDFile<pcl::PointXYZI>(filename, cloud_in);
points.reserve(cloud_in.size());
@@ -415,8 +415,8 @@ void PcdReader::read(const std::string& filename)
points.push_back(Base::Vector3d(it->x,it->y,it->z));
intensity.push_back(it->intensity);
}
}
else if (hasNormals) {
}
else if (hasNormals) {
pcl::PointCloud<pcl::PointNormal> cloud_in;
pcl::io::loadPCDFile<pcl::PointNormal>(filename, cloud_in);
points.reserve(cloud_in.size());
@@ -425,15 +425,15 @@ void PcdReader::read(const std::string& filename)
points.push_back(Base::Vector3d(it->x,it->y,it->z));
normals.push_back(Base::Vector3f(it->normal_x,it->normal_y,it->normal_z));
}
}
else {
}
else {
pcl::PointCloud<pcl::PointXYZ> cloud_in;
pcl::io::loadPCDFile<pcl::PointXYZ>(filename, cloud_in);
points.reserve(cloud_in.size());
for (pcl::PointCloud<pcl::PointXYZ>::const_iterator it = cloud_in.begin();it!=cloud_in.end();++it) {
points.push_back(Base::Vector3d(it->x,it->y,it->z));
}
}
}
}
#endif
@@ -503,11 +503,11 @@ PlyWriter::~PlyWriter()
void PlyWriter::write(const std::string& filename)
{
bool hasIntensity = (intensity.size() == points.size());
bool hasColors = (colors.size() == points.size());
bool hasNormals = (normals.size() == points.size());
bool hasIntensity = (intensity.size() == points.size());
bool hasColors = (colors.size() == points.size());
bool hasNormals = (normals.size() == points.size());
if (hasNormals && hasColors) {
if (hasNormals && hasColors) {
pcl::PointCloud<pcl::PointXYZRGBNormal> cloud_out;
cloud_out.reserve(points.size());
@@ -533,8 +533,8 @@ void PlyWriter::write(const std::string& filename)
}
pcl::io::savePLYFile<pcl::PointXYZRGBNormal>(filename, cloud_out);
}
else if (hasNormals && hasIntensity) {
}
else if (hasNormals && hasIntensity) {
pcl::PointCloud<pcl::PointXYZINormal> cloud_out;
cloud_out.reserve(points.size());
@@ -557,8 +557,8 @@ void PlyWriter::write(const std::string& filename)
}
pcl::io::savePLYFile<pcl::PointXYZINormal>(filename, cloud_out);
}
else if (hasColors) {
}
else if (hasColors) {
pcl::PointCloud<pcl::PointXYZRGBA> cloud_out;
cloud_out.reserve(points.size());
@@ -580,8 +580,8 @@ void PlyWriter::write(const std::string& filename)
}
pcl::io::savePLYFile<pcl::PointXYZRGBA>(filename, cloud_out);
}
else if (hasIntensity) {
}
else if (hasIntensity) {
pcl::PointCloud<pcl::PointXYZI> cloud_out;
cloud_out.reserve(points.size());
@@ -600,8 +600,8 @@ void PlyWriter::write(const std::string& filename)
}
pcl::io::savePLYFile<pcl::PointXYZI>(filename, cloud_out);
}
else if (hasNormals) {
}
else if (hasNormals) {
pcl::PointCloud<pcl::PointNormal> cloud_out;
cloud_out.reserve(points.size());
@@ -620,11 +620,11 @@ void PlyWriter::write(const std::string& filename)
pn.normal_z = n.z;
cloud_out.push_back(pn);
}
}
}
pcl::io::savePLYFile<pcl::PointNormal>(filename, cloud_out);
}
else {
}
else {
pcl::PointCloud<pcl::PointXYZ> cloud_out;
cloud_out.reserve(points.size());
for (Points::PointKernel::const_iterator it = points.begin(); it != points.end(); ++it) {
@@ -634,7 +634,7 @@ void PlyWriter::write(const std::string& filename)
}
pcl::io::savePLYFile<pcl::PointXYZ>(filename, cloud_out);
}
}
}
// ----------------------------------------------------------------------------
@@ -649,11 +649,11 @@ PcdWriter::~PcdWriter()
void PcdWriter::write(const std::string& filename)
{
bool hasIntensity = (intensity.size() == points.size());
bool hasColors = (colors.size() == points.size());
bool hasNormals = (normals.size() == points.size());
bool hasIntensity = (intensity.size() == points.size());
bool hasColors = (colors.size() == points.size());
bool hasNormals = (normals.size() == points.size());
if (hasNormals && hasColors) {
if (hasNormals && hasColors) {
pcl::PointCloud<pcl::PointXYZRGBNormal> cloud_out;
cloud_out.reserve(points.size());
@@ -675,13 +675,13 @@ void PcdWriter::write(const std::string& filename)
pn.b = c.b * 255.0f;
cloud_out.push_back(pn);
}
cloud_out.width = width;
cloud_out.height = height;
cloud_out.width = width;
cloud_out.height = height;
pcl::io::savePCDFile<pcl::PointXYZRGBNormal>(filename, cloud_out);
}
else if (hasNormals && hasIntensity) {
}
else if (hasNormals && hasIntensity) {
pcl::PointCloud<pcl::PointXYZINormal> cloud_out;
cloud_out.reserve(points.size());
@@ -700,13 +700,13 @@ void PcdWriter::write(const std::string& filename)
pn.intensity = intensity[index];
cloud_out.push_back(pn);
}
cloud_out.width = width;
cloud_out.height = height;
cloud_out.width = width;
cloud_out.height = height;
pcl::io::savePCDFile<pcl::PointXYZINormal>(filename, cloud_out);
}
else if (hasColors) {
}
else if (hasColors) {
pcl::PointCloud<pcl::PointXYZRGBA> cloud_out;
cloud_out.reserve(points.size());
@@ -724,13 +724,13 @@ void PcdWriter::write(const std::string& filename)
pc.b = c.b * 255.0f;
cloud_out.push_back(pc);
}
cloud_out.width = width;
cloud_out.height = height;
cloud_out.width = width;
cloud_out.height = height;
pcl::io::savePCDFile<pcl::PointXYZRGBA>(filename, cloud_out);
}
else if (hasIntensity) {
}
else if (hasIntensity) {
pcl::PointCloud<pcl::PointXYZI> cloud_out;
cloud_out.reserve(points.size());
@@ -745,13 +745,13 @@ void PcdWriter::write(const std::string& filename)
pi.intensity = intensity[index];
cloud_out.push_back(pi);
}
cloud_out.width = width;
cloud_out.height = height;
cloud_out.width = width;
cloud_out.height = height;
pcl::io::savePCDFile<pcl::PointXYZI>(filename, cloud_out);
}
else if (hasNormals) {
}
else if (hasNormals) {
pcl::PointCloud<pcl::PointNormal> cloud_out;
cloud_out.reserve(points.size());
@@ -769,23 +769,23 @@ void PcdWriter::write(const std::string& filename)
pn.normal_z = n.z;
cloud_out.push_back(pn);
}
cloud_out.width = width;
cloud_out.height = height;
cloud_out.width = width;
cloud_out.height = height;
pcl::io::savePCDFile<pcl::PointNormal>(filename, cloud_out);
}
else {
}
else {
pcl::PointCloud<pcl::PointXYZ> cloud_out;
cloud_out.reserve(points.size());
for (Points::PointKernel::const_iterator it = points.begin(); it != points.end(); ++it) {
cloud_out.push_back(pcl::PointXYZ(it->x, it->y, it->z));
}
cloud_out.width = width;
cloud_out.height = height;
cloud_out.width = width;
cloud_out.height = height;
pcl::io::savePCDFile<pcl::PointXYZ>(filename, cloud_out);
}
}
}
#endif

View File

@@ -27,7 +27,7 @@
# include <QObject>
# include <QEvent>
# include <QMutex>
# include <QMutexLocker>
# include <QMutexLocker>
# include <QSemaphore>
# include <QThread>
# include <QWaitCondition>
@@ -253,18 +253,18 @@ void DocumentProtector::init()
DocumentReceiver::globalInstance()->
moveToThread(QCoreApplication::instance()->thread());
}
void DocumentProtector::slotDeletedDocument(const App::Document& Doc)
{
if (&Doc == getDocument()) {
this->detachDocument();
}
}
void DocumentProtector::slotDeletedDocument(const App::Document& Doc)
{
if (&Doc == getDocument()) {
this->detachDocument();
}
}
void DocumentProtector::validate()
{
if (!this->getDocument())
throw Base::Exception("Handled document is null");
throw Base::ValueError("Handled document is null");
}
App::DocumentObject *DocumentProtector::addObject(const std::string& type, const std::string& name)
@@ -303,7 +303,7 @@ DocumentObjectProtector::~DocumentObjectProtector()
void DocumentObjectProtector::validate()
{
if (!obj)
throw Base::Exception("Handled document object is null");
throw Base::ValueError("Handled document object is null");
}
App::DocumentObject* DocumentObjectProtector::getObject() const