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");
}
0

1 Answer 1

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");
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.