Exceptions doubt
I'm programming exceptions.
In one file, I have:
if(...)
throw(Map_nonExisting());
And, in Exceptions.hxx I have:
class Map_noneExisting : public std::exception
{
public:
const char * what() const throw ()
{
return "There is no Mappings existing";
}
};
This compile but don't run correctly...
Anybody know where have I an error??
Help me please, I'm desesperated!!
[476 byte] By [
salva.tb] at [2007-11-20 11:10:07]

# 1 Re: Exceptions doubt
In your ctor for Map_noneExisting
are you calling the base class ctor?
you should be!
something like
MyException::MyException(const std::string msg) :
exception(),
msg_(msg)
{
}
also..
The'what' function is virtual, you should add that keyword to the function declaration
wuhoo at 2007-11-10 22:26:47 >

# 2 Re: Exceptions doubt
I don't understund what do you mean. Which is the ctor class?? I don't have to create a Map_nonExisting class??
My base class is "exception"
# 3 Re: Exceptions doubt
You are creating a class called 'Map_noneExisting'
This class extends exception. Correct?
So in your header you have
class Map_noneExisting: public exception
{
public:
Map_noneExisting();
virtual const char *what() const;
protected:
// methods
private:
// methods
};
The first public method there is the Constructor(ctor)
Correct?
Can you post all of your code, it cant be that long.
Post the header and the .cpp
This compile but don't run correctly...
Anybody know where have I an error??
This isnt very discriptive, wither post all your code or give a more detailed explanation of your problem
wuhoo at 2007-11-10 22:28:45 >

# 4 Re: Exceptions doubt
Here I send all the important code for my question.
Visual compile and link correctly this code. But, when I need to run the code, at throw name_exception(); the code crashes.
Previous, a lot of thanks for your help.
code of Exceptions.hxx here:
------------
#ifndef _Exceptions_hxx_
#define _Exceptions_hxx_
#include <sstream>
#include <string>
class APhI_noneExisting : public std::exception
{
public:
virtual const char * what() const throw ()
{
return "There is no APhIs existing";
}
};
class Map_noneExisting : public std::exception
{
public:
const char * what() const throw ()
{
return "There is no Mappings existing";
}
};
class APhI_notFound : public std::exception
{
public:
const char * what() const throw ()
{
return "APhI non-existent";
}
};
class Map_notFound : public std::exception
{
public:
const char * what() const throw ()
{
return "Mapping non existent";
}
};
class APhI_alreadyExisting : public std::exception
{
public:
const char * what() const throw ()
{
return "APhI already existent";
}
};
#endif
------------------
code of the conflicting part of icm.cpp here:
------------------
#include "icm.h"
Icm::Icm(){
}
/*
methods
*/
void Icm::Work()
{
APhI * a;
if ( aphis.size() == 0 )
throw (APhI_noneExisting());
if ( maps.size() == 0)
throw Map_noneExisting();
}
-------
And icm.h code
-------
#ifndef ICM_H
#define ICM_H
/*
includes
*/
#include "Exceptions.hxx"
using namespace std;
class Icm {
private:
Groups _groups;
Modifiers _modifiers;
APhIs aphis;
Maps maps;
public:
Icm();
void work();
};
# 5 Re: Exceptions doubt
Here I send all the important code for my question.
Visual compile and link correctly this code. But, when I need to run the code,You didn't post the code that duplicates the error (the main() program). You just posted the classes.
What is Groups? What is Modifiers? When posting code that doesn't run correctly, post the smallest example that has *all* of the necessary files so that the code can compile and run without any modification.
Also mention the compiler and compiler version that you're using, as this is sometimes important when dealing with these issues.
Also, please use code tags when posting code.
#ifndef _Exceptions_hxx_
#define _Exceptions_hxx_
#include <sstream>
#include <string>
class APhI_noneExisting : public std::exception
{
public:
virtual const char * what() const throw ()
{
return "There is no APhIs existing";
}
};
class Map_noneExisting : public std::exception
{
public:
const char * what() const throw ()
{
return "There is no Mappings existing";
}
};
class APhI_notFound : public std::exception
{
public:
const char * what() const throw ()
{
return "APhI non-existent";
}
};
class Map_notFound : public std::exception
{
public:
const char * what() const throw ()
{
return "Mapping non existent";
}
};
class APhI_alreadyExisting : public std::exception
{
public:
const char * what() const throw ()
{
return "APhI already existent";
}
};
#endif
------------------
code of the conflicting part of icm.cpp here:
------------------
#include "icm.h"
Icm::Icm(){
}
/*
methods
*/
void Icm::Work()
{
APhI * a;
if ( aphis.size() == 0 )
throw (APhI_noneExisting());
if ( maps.size() == 0)
throw Map_noneExisting();
}
-------
And icm.h code
-------
#ifndef ICM_H
#define ICM_H
/*
includes
*/
#include "Exceptions.hxx"
using namespace std;
class Icm {
private:
Groups _groups;
Modifiers _modifiers;
APhIs aphis;
Maps maps;
public:
Icm();
void work();
};
See how code tags work?
Regards,
Paul McKenzie
