exeption inside a constructor-please help!

Hi everybody,

my following code is trying to produce a expection while the value of R entred by the user(inside the constructor) is negative.

when i use this code and throw a string i recieve this failure:"char at memory location 0x0012ff0c.." while the program is running and a negative value entred by the user.
while throwing an integer instead , the program works properly.
please help!

//circle.h
class circle{
int x;
int y;
int R;
public:
circle(int Ix,int Iy,int IR);
//~circle();
void show(){
cout<<x<<endl<<y<<endl<<R<<endl;

}

};
//circle.cpp
#include<iostream>
using namespace std;
#include "circle.h"


circle::circle(int Ix,int Iy,int IR){
x=Ix;
y=Iy;
R=IR;
if (IR<=0){

throw "no negative values are permitted";
}



}
//circle::~circle(){

//}
//the main cpp
#include<iostream>
using namespace std;
#include "circle.h"

int main(){

int x,y,R;

cout<<"please enter parametres"<<endl;
cin>>x>>y>>R;
try{
circle one(x,y,R);
one.show();
}
catch(char *msg){
cout<<msg<<endl;
}

system("pause");
return 0;
}
Last edited on
Catch a const char* instead.
Topic archived. No new replies allowed.