I am using Visual C++ 2005 (native C++)
For the following code, the different of main function 1 and main function 2 is
main function 1 using
}catch(MyException &e){
but main function 2 using
}catch(MyException e){
Which is more correct? if both are correct, which is better?
//========This is MyException.h=====
#pragma once
#include <string>
using std::string;
class MyException
{
public:
MyException(void);
MyException(string);
virtual ~MyException(void);
string getMsg(void);
private:
string msg;
};
//=======This is MyException.cpp========
#include "MyException.h"
MyException::MyException(void):msg("")
{
}
MyException::MyException(string exceptionMsg):msg(exceptionMsg)
{
}
string MyException::getMsg(){
return msg;
}
MyException::~MyException(void)
{
}
//======this is main function 1=======
try{
int i=1;
throw MyException("sth wrong");
}catch(MyException &e){
cout<<e.getMsg()<<endl;
}
//======this is main function 2======
try{
int i=1;
throw MyException("sth wrong");
}catch(MyException e){
cout<<e.getMsg()<<endl;
}