Link to home
Start Free TrialLog in
Avatar of Roger Alcindor
Roger Alcindor

asked on

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.
Avatar of chensu
chensu
Flag of Canada image

SetErrorMode
Avatar of basant
basant

You can use Structure Exception handling for that (SEH)
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.
Avatar of Roger Alcindor

ASKER

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 ?
}
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your help, can you explain the significance of __try as opposed to try ?

Keep up the good work - Roger
__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.
try/catch is used for standard C++ exception handling while __try/__except is used for the Structured Exception Handling (SEH) in Windows.