1

I am working with the EurekaLog bug catcher for Delphi/C++Builder. All of their examples are in Delphi and I am using C++Builder. The Delphi code below is one of their examples that causes a software exception. I tried to convert this into C++ below but my code is wrong. Can you show me the correct C++ Code to make this work.

Delphi code from EurekaLog

type
  EMyException = class(Exception);

Procedure TForm. ButtonClick(Sender: TObject);
begin
 raise EMyException.Create('Error Message');
end;

end.

My C++Builder code that does not work

typedef class{
  Exception;
}EMyException;

void __fastcall TForm1::ButtonClick(TObject *Sender)
{
  throw new EMyException("Error Message");
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
homebase
  • 713
  • 1
  • 6
  • 20

1 Answers1

4

You need to derive a new class, not use a typedef. And don't use new when calling throw (this is the only area in C++Builder where a TObject descendant must not be constructed with new).

class EMyException : public Exception
{
public:
    __fastcall EMyException(const String Msg) : Exception(Msg) {}
};

void __fastcall TForm::ButtonClick(TObject *Sender)
{
    throw EMyException("Error Message");
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770