Q:

Error in class type as an exception in c++

Whenever I try this code to catch class type as exception I get an error message as "deprecated conversion from string constant to 'char*'" .
Why is it so and how can it be avoided?
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
class Error
{
 int err_code;
 char *err_desc;
public:
       Error(int c , char* p)
        {
           err_code=c;
           err_desc=new char(strlen(p));
           strcpy(err_desc,p);
        }
        void display(void)
         {
           cout<<err_code<<"done successfully"<<err_desc;
          }
      };
 int main()
{
int x;
try
 {
  cout<<"\n press any key to avoid exception except 99";
  cin>>x;
  if(x=99)
  throw Error(x,"Exception");
 }
catch (Error e )
 {

   cout<<"\n exception caught successfully";
   e.display();
  }

  return 0;
}

A:

A string literal should be passed into a const char* not a char* (the former is the correct type) so change the constructor signature to
Error(int c , const char* p);

and the member variable to
const char *err_desc;

Or you can pass around std::string, which I would recommend.

