Working BCB4 O/S Exception handler needed

I need a handler for a BCB 4 application ( win 32 ) which will allow me to do the following :-

1 - stop the default operating system exception handler from displaying a dialogue box on the screen.

2 - give my application ( thread ) notification of the exception and pass back an "Abort" to the operating system which is Windows NT workstation 4.

My thread is testing a floppy disk by writing a file to it and I need to detect whether or not a diskette is present and to handle exceptions.
There is NO video MONITOR , this is an indutrial application that uses a serial driven text display device so I don't want to have dialogue boxes displayed that expect a mouse-click to continue program execution.
Points will only be awarded for working code - NO referrals please !
Thanks - Roger
PS. I have tried using the Borland Help examples but they don't work for me.
LVL 2
Roger AlcindorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
SetErrorMode
0
basantCommented:
You can use Structure Exception handling for that (SEH)
0
MadshiCommented:
chensu is right.

This is what I'm calling in the initialiazion of my IO tools unit:

  SetErrorMode(SEM_FAILCRITICALERRORS or SEM_NOOPENFILEERRORBOX);

Regards, Madshi.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Roger AlcindorAuthor Commented:
This only answers the first part of the question.
I need to catch the exception so that I can determine what the failure was ( eg , no diskette in the drive, diskette write protected, write or read failure etc .. ? )

The following is my code (BCB4) for a thread that does the testing - or rather will do when I can sort it out :-

#include <excpt.h>
#pragma package(smart_init)

int filter_func(EXCEPTION_POINTERS *);
EXCEPTION_POINTERS *xp;
extern bool testrequested;

__fastcall test::test(bool CreateSuspended)
        : TThread(CreateSuspended)
{
        SetErrorMode(SEM_FAILCRITICALERRORS);
        FreeOnTerminate = true;
}
//---------------------------------------------------------------------------
void __fastcall test::Execute()
{
   for(;Terminated==false;)
   {
         if(testrequested)
         {
             testrequested = false; // one-shot
             try
             {  // we get here as expected
             fp = fopen("a:\\test","w");
             }
             // the following never gets invoked ?
             __except(filter_func(xp = GetExceptionInformation()))
             {
             }
         }
   }
}
//---------------------------------------------------------------------------
int filter_func(EXCEPTION_POINTERS *)
{ // should be able to determine exception cause here ?
 return  1; // this never gets invoked either ?
}
0
chensuCommented:
fopen does not throw an exception. You need to check the return value of fopen. In order to find out the error cause, you should use the Win32 file functions instead, such as CreateFile, and call GetLastError to get the error information. Try the following code.

__try     // Use __try instead of try!!!
{  // we get here as expected
    FILE *fp = fopen("a:\\test","w");   // NO exception
    // check the value of fp

    char *p = NULL;
    *p = 'a';    // EXCEPTION_ACCESS_VIOLATION
}
// the following never gets invoked ?
__except(filter_func(GetExceptionInformation()))
{
}


int filter_func(EXCEPTION_POINTERS *ep)
{ // should be able to determine exception cause here ?
    switch (ep->ExceptionRecord.ExceptionCode)
    {
        case EXCEPTION_ACCESS_VIOLATION:
            // ...
            break;
        // ...
    }

    return  1; // this never gets invoked either ?
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roger AlcindorAuthor Commented:
Thanks for your help, can you explain the significance of __try as opposed to try ?

Keep up the good work - Roger
0
basantCommented:
__try is OS dependent exception handling which catches OS exception too which are not necessarily a C++ exception. These codes are usually not portable. This is called Structure Exception Handling (SEH).

I tried to answer ur question first. Though I didn't explain it clearly.
0
chensuCommented:
try/catch is used for standard C++ exception handling while __try/__except is used for the Structured Exception Handling (SEH) in Windows.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.