Networking Forums

Networking Forums > Computer Networking > Windows Networking > C++ Exceptions Question

Reply
Thread Tools Display Modes

C++ Exceptions Question

 
 
Tom Bruce
Guest
Posts: n/a

 
      11-20-2003, 11:53 PM
I created the following code segment which recreates an interesting problem
with C++ exceptions. I am using Visual Studio C++ 6.0 Enterprise Edition.
When the program runs in DEBUG mode the exception is caught in the F2
function handler as I would expect. However when the program runs in
RELEASE mode the exeption is caught in the F1 function handler. The command
that is throwing the exception is the strcspn(). Why does this occur?

//-----------------------------------------------------------------
#include <iostream.h>
#include <string.h>

class EClass
{
public:
void F1(const char* a);
void F2(const char* b);
};

void EClass::F1(const char* a)
{
try
{
F2(a);
}
catch(...)
{
cout << "caught in F1 handler" << endl;
}
}

void EClass::F2(const char* a)
{
int i;
char* b = NULL;

try
{
b = strstr(a, "Test");
i = strcspn(b, "\r\n");
}
catch(...)
{
cout << "caught in F2 handler" << endl;
}
}

int main(int argc, char* argv[])
{
EClass ec;
char a[200];
strcpy(a,"Tes\r\n");

try
{
ec.F1(a);
}
catch(...)
{
cout << "caught in main handler" << endl;
}
return 0;
}
//-----------------------------------------------------------------

Tom


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.542 / Virus Database: 336 - Release Date: 11/18/2003


 
Reply With Quote
 
 
 
 
Steve Maillet \(eMVP\)
Guest
Posts: n/a

 
      11-23-2003, 03:17 PM
Because you didn't specify Asynchronous exceptions using /EHa if you don't
the compiler assumes that exceptions are only thrown on function calls or on
throw statements but not on individual instructions.

BTW: This has nothing to do with networking.
Follow up is set to the vc.language group.

--
Steve Maillet (eMVP)
Entelechy Consulting
smaillet_AT_EntelechyConsulting_DOT_com


 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File & Printer Sharing not listed under Firewall Exceptions Haris.Hadzimuratovic@gmail.com Wireless Internet 11 11-16-2006 05:06 PM
Svchost Firewall exceptions MikeV06 Windows Networking 0 12-06-2005 12:54 PM
vredir & ifsmgr fatal exceptions Jim Wolfe Windows Networking 0 06-18-2004 11:38 AM
C++ Exceptions Question Tom Bruce Windows Networking 3 11-23-2003 03:17 PM
C++ Exceptions Question Tom Bruce Windows Networking 3 11-23-2003 03:17 PM



1 2 3 4 5 6 7 8 9 10 11