LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

In CVI,how to realize the __try{...}__except{...} function in vc++? urgent!!!

I want to test a card in my pc.But if the card is no in my pc,when i execute the exe file,it will break out and will not continue.....
How to avoid this problem that it will popup a messeage and continue to execute instead of break out and interrupt?
if I use VC++,I can use __try{}__except(..){}
,which can handle the fatal exception.
but, how can I do the same in CVI???

thanks for any of your reply
0 Kudos
Message 1 of 9
(6,161 Views)
Exceptions are a C++ method of error handling and LabWindows/CVI is a ANSI C compiler, not C++. Therefore, you can't do exception handling in CVI.

Best Regards,

Chris Matthews
Measurement Studio Support Manager
0 Kudos
Message 2 of 9
(6,161 Views)
Chris,

I totally agree with your answer BUT does this still stand? I mean is there no way to trap exception errors in CVI?

Thanks
John
0 Kudos
Message 3 of 9
(6,161 Views)
Greetings,

In CVI as in any other C compiler, error handling is done with if-then-else statements, error macros or goto statments. As an example, the following function does error checking and cleanup with a goto statement:

int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpszCmdLine, int nCmdShow)
{
if (InitCVIRTE (hInstance, 0, 0) == 0)
return -1; /* out of memory */
SetSleepPolicy(VAL_SLEEP_MORE);
// Load and Display Panel
if ((panelHandle = LoadPanel (0, "OnePanel.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
// Setup critical section
if (SetupApplication() < 0)
goto Error;
// Wait for user input
RunUserInterface ();

Er
ror:
// Terminates the threads if needed
ShutdownApplication();
return 0;
}

To handle the fatal exception you mentioned, you'll need to monitor every return value and jump to a goto statement (emulating a catch statement) whenever the error pops up. You can post your try-catch block if you need additional help.

Regards,
Azucena
Message 4 of 9
(6,161 Views)
CVI remains a development environment for the ANSI C language so you can't catch and respond to exceptions in your code since that is the C++ method of error handling. You can't compile C++ code in CVI, so any exceptions you get must be from modules (DLLs, etc) that are already compiled and should be setup to handle their exceptions internally. There is an option in the Options->Run Options... settings that controls whether your program will break while debugging if it causes an exception.

Hope that helps,

Chris Matthews
National Instruments
0 Kudos
Message 5 of 9
(6,161 Views)
Chris,

Like I said before I agree with your earlier answer but in looking at Microsofts MSDN Library they added what they called "structured exceptions". These are MS extensions.

Snippet from MSDN:
The try-except statement is a Microsoft extension to the C and C++ languages that enables 32-bit target applications to gain control when events that normally terminate program execution occur. Such events are called exceptions, and the mechanism that deals with exceptions is called structured exception handling.

I guess I was asking if NI had added something like this.
0 Kudos
Message 6 of 9
(6,161 Views)
I believe the structured exceptions are only available through the VC++ compiler. This is Microsoft's technology, so it is unlikely NI will ever add this to CVI.

Regards,
Azucena
0 Kudos
Message 7 of 9
(6,161 Views)
No, CVI doesn't support structured event handling. It's true that some C compilers do have structured event handling support (so does Visual Basic.NET now as well). We don't have it in the CVI compiler though.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 8 of 9
(6,161 Views)
Hasn't the try-catch-throw exception handling mechanism been a part of "ANSI C" for the past few years, in addition to C++?
0 Kudos
Message 9 of 9
(6,161 Views)