Question and Answer Database FAQ1857C.txt Exception Handling and VCL Category :VCL Platform :All Product :C++Builder 1.x Question: Is there a simple way to catch exceptions in the control's events? Answer: Create a method of the form to trap for exceptions. This method will be called on the OnException method of the application. In your method, check for the exception you're looking for, ie EDatabaseError. Check the on-line help for the OnException event. It has info on how to call your own method for the event. For example: void __fastcall TForm1::MyException(TObject *Sender, Exception *E) { // Don't forget to do a forward declaration for this in the class // definition. if (dynamic_cast(E)) { MessageBox(0, E->Message.c_str(), "Trapped Exception", MB_OK); } else { // This is not the error you are looking for, Raise the exception. // ... } } void __fastcall TForm1::FormCreate(TObject *Sender) { Application->OnException = MyException; } 7/2/98 10:32:32 AM
Last Modified: 01-SEP-99