C++ Builder IDE >> exception capturing

by srinivas » Thu, 22 Dec 2005 13:20:59 GMT



If new operator is failed the borland raising the exception and displaying message box
how can i catch that exception before borland it self display the message box

thanks
srinivas


C++ Builder IDE >> exception capturing

by Andrue Cope [TeamB] » Thu, 22 Dec 2005 16:59:46 GMT






This is really a C++ language issue so would be best asked in
.cpp.language but the answer is to use the language construct
try..finally.

For more information please ask in .cpp.language

--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html



C++ Builder IDE >> exception capturing

by Remy Lebeau (TeamB) » Thu, 22 Dec 2005 18:17:08 GMT






I think you mean a try..catch, don't you? A try..finally won't stop the
exception from continuing up the call stack after the finally block exits.


Gambit




exception capturing

by Remy Lebeau (TeamB) » Thu, 22 Dec 2005 18:21:57 GMT






Wrap the allocation in a try..catch block. However, what you actually catch
depends on what you are allocating in the first place. The 'new' operator
is supposed to throw a std::bad_alloc exception when it fails, ie:

try
{
// use 'new' as needed ....
}
catch(const std::bad_alloc &)
{
// handle the failure as needed....
}

Or:

try
{
// use 'new' as needed ....
}
catch(const std::exception &)
{
// handle the failure as needed....
}

Or:

try
{
// use 'new' as needed ....
}
catch(...)
{
// handle the failure as needed....
}

However, if you are allocating a VCL object, then you will usually get a VCL
Exception instead because the VCL memory manager is used instead of the
C/C++ memory manager.

try
{
// use 'new' as needed ....
}
catch(const Exception &)
{
// handle the failure as needed....
}

Or you can combine them all:

try
{
// use 'new' as needed ....
}
catch(const Exception &)
{
// handle the VCL exception as needed....
}
catch(const std::exception &)
{
// handle the standard exception as needed....
}
catch(...)
{
// handle everything else as needed....
}


Gambit




exception capturing

by Andrue Cope [TeamB] » Thu, 22 Dec 2005 18:37:14 GMT





Oops, yes. Why on Earth did I type 'finally'? I've not used that for
years. Must be getting too close to the holidays :-/

--
Andrue Cope [TeamB]
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html


Similar Threads

1. Capturing TidTCPClient disconnect event or exception

I have a Server/Client app/protocol working well, but both need to be stand-alone. 

Occasionally the connection gets dropped and the Client computer brings up a modal Windows error message describing why it disconnected. 

In my particular application, there won't be anyone there to accept the message and try to reconnect. 

Using the ONDISCONNECT client event doesn't work because the modal message hits before the event. 

I have a try/except around the place I actually do the connect, but it doesn't fire unless there is a problem in the initial connection. 

I figure the solution has something to do with the client Intercept or IOHandler Events(?), but I can't find any examples or descriptions on how to use them. 

Any assistance would be greatly appreciated, especially if it includes where I can look for this kind of information without bothering anyone. 

Thanks in advance 

Hank Arnold

2. Can't capture idHTTP exceptions??

3. TDirectoryListBox->Drive, capturing an exception using try

Hello,  I want to capture the error message in TDirectoryListBox when you 
assign a non-existant drive to TDirectoryListBox->Drive.  That way I can 
iterate true all 26 letters of the alphabet to get the good drives.  So I 
dont want the user to see any error messages.  I am sure the try/catch block 
would work but i dont know how to use it please help.

Thanks 


4. Lib to capture call tree on an exception?

5. Capturing stack trace on exception

I have a Windows CE 5.0 application in which I've installed an exception 
filter (code at the bottom of this post) that generates output like this:

H 2006/11/14 12:22:42 Exception 0xC0000005 at address 0x000A4B10.
H 2006/11/14 12:22:42 ExceptionInformation[0] = 0x00000000.
H 2006/11/14 12:22:42 ExceptionInformation[1] = 0x0E00006C.

or this:

H 2006/11/16 09:18:46 Exception 0x80000002 at address 0x03F821D8.

I can interpret the messages, but the problem I have is that I don't get 
much information about the context.

Is it possible to get a stack trace and register dump in the exception 
filter?  If so, is sample code available?  Any help on this would be 
appreciated.

///
// Exception filter; uses only the most basic C functions to record the 
error.
int exceptionFilter(unsigned int code, _EXCEPTION_POINTERS * 
exceptionPointers)
{
EXCEPTION_RECORD * exceptionRecord = exceptionPointers->ExceptionRecord;

char errorLogFileName[MAX_PATH];
strcat(strcpy(errorLogFileName, TAppConfig::appConfig.dataDirectory()), 
"error.log");

FILE * errorLogF = fopen(errorLogFileName, "ab");
if (errorLogF != 0)
   {
   SYSTEMTIME systemTime;
   GetLocalTime(&systemTime);

   fprintf(errorLogF, "H %04hu/%02hu/%02hu %02hu:%02hu:%02hu Exception 0x%08X at address 0x%08X.\r\n", systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, systemTime.wMinute, systemTime.wSecond, code, exceptionRecord->ExceptionAddress);

   for (DWORD index = 0; index < exceptionRecord->NumberParameters; index++)
     fprintf(errorLogF, "H %04hu/%02hu/%02hu %02hu:%02hu:%02hu ExceptionInformation[%d] = 0x%08X.\r\n", systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, systemTime.wMinute, systemTime.wSecond, index, exceptionRecord->ExceptionInformation[index]);

   fclose(errorLogF);
   }

return EXCEPTION_EXECUTE_HANDLER;
}

6. How to capture mouse during screen capture

7. Exceptions, Exceptions, Exceptions :D

Hmmm

Since I catch the exception... I should be able to continue the program
lol...

But when calling 'get game list' for a second time it will say: connection
already open.

This might be a good example where to include try... finally;

Let's try to think up an example/pseudo code:

try
    try
        Connection.Open;

        ExecuteSql;

    except

    end;

finally

    Connection.Close;

end;

BUT WHAT THE FUCK ABOUT WHEN THE Connection.Open fails ?!

Calling Connection.Close is not wise if connection.open failed !

SO THIS SUCKS

ANOTHER STUPID EXAMPLE OF EXCEPTIONS !

Hmmm let s see maybe try finally is just retarded... and we should use
something else instead.

We could still use try finally.

try

    try
        Connection.Open;

        ExecuteSQL;

    except


    end;

finally

    try
        Connection.Close
    except

    end;

end;

Ieeewwwww..

Am I supposed to program like this ?

Ofcourse this code will probably not work...

Since if Connection.Open fails... it will raise an exception... and that
exception will be caught by the first

exception handler.. so finally will probably never be reached !

Hmmm maybe that's a good thing :)

Since I dont want to call Connection.Close if open fails.

Oh well let's see if that works :D

Skybuck.


8. Sample program: Try / Catch exceptions user defined exceptions derived from System.Exception - CSharp/C#