Home > Software engineering >  Vs2010 try catch is invalid?
Vs2010 try catch is invalid?

Time:10-07

Vs2010, using MFC to do a thing, found the try and catch to catch exceptions, the original vs2008 can be set by the project properties - & gt; C + + - & gt; Code generation - & gt; Enable c + + exception is set to: yes, but there are SEH exception (/EHa), and can catch exceptions, but not 2010, friend ever encountered the same problem can give a solution, thank you very much,

Void CaDlg: : OnBnClickedOk ()
{
Try
{
Int * a=NULL;
* a=1;
}
The catch (CMemoryException * e)
{
AfxThrowMemoryException ();
AfxMessageBox (" DDDDDDDDDDDDD ", MB_OK);
}
The catch (CFileException * e)
{
AfxThrowFileException (CFileException: : fileNotFound);
AfxMessageBox (" DDDDDDDDDDDDD ", MB_OK);
}
The catch (CException * e)
{
Throw;
AfxMessageBox (" DDDDDDDDDDDDD ", MB_OK);
}
}

CodePudding user response:

with SEH __try __except capture

CodePudding user response:

See I was just looking at the snow and post the same content o

CodePudding user response:

reference 1st floor zgl7903 response:
with SEH __try __except capture


That's my hair, __try and __except can be caught, but want to use the catch, it's very entanglements, original vs2008 platform is no problem,

CodePudding user response:

You add a catch (... Try)?

CodePudding user response:

Or you changed the/EHa to/EHsc try?

CodePudding user response:

reference 5 floor BeanJoy reply:
or you changed the/EHa to try/EHsc?


invalid

CodePudding user response:

Sometimes not to "call a function name + each parameter value, after entering the function of each parameter values, intermediate variable values, exit the function return value of preparation, return to the function to call after the function value of the parameter name + + return value" this information to write logs to a file is where no matter how to also can not find the problem, including the capture all kinds of abnormal , write the log to the screen and single step or set a breakpoint or generated the core or the DMP file,... These methods are not! Write logs to a file reference below:
//loop to a function sends a length of 200 bytes (this is the fixed) buffer, 
//a function need to incoming buffer, the circulation of 240 bytes (fixed) new buffer for processing,
//when dealing with each new printing takes two bytes of the buffer
# ifdef _MSC_VER
# pragma warning (4996) disable:
# endif
#include
#include
#include
# ifdef _MSC_VER
#include
#include
#include
# define MYVOID void
# define vsnprintf _vsnprintf
# the else
#include
#include
#include
# define CRITICAL_SECTION pthread_mutex_t
# define MYVOID void *
# endif
//the Log {
# define MAXLOGSIZE 20000000
# define MAXLINSIZE 16000
#include
#include
#include
Char logfilename1 []="MyLog1. Log";
Char logfilename2 []="MyLog2. Log";
The static char logstr [MAXLINSIZE + 1];
Char datestr [16].
Char timestr [16].
Char MSS [4].
CRITICAL_SECTION cs_log;
The FILE * flog;
# ifdef _MSC_VER
The Lock (CRITICAL_SECTION void * l) {
The EnterCriticalSection (l);
}
Void Unlock (CRITICAL_SECTION * l) {
LeaveCriticalSection (l);
}
Void sleep_ms (int) ms {
Sleep (ms).
}
# the else
The Lock (CRITICAL_SECTION void * l) {
Pthread_mutex_lock (l);
}
Void Unlock (CRITICAL_SECTION * l) {
Pthread_mutex_unlock (l);
}
Void sleep_ms (int) ms {
Usleep (ms * 1000);
}
# endif
Void LogV (const char * pszFmt, va_list argp) {
* struct tm now;
Struct timeb TB;

If (NULL==pszFmt | | 0==pszFmt [0]) return;
Vsnprintf (logstr, MAXLINSIZE pszFmt, argp);
Ftime (& amp; TB);
Now=localtime (& amp; TB. Time);
Sprintf (datestr, "% d % % 4 d - 02-02 d", now - & gt; Tm_year + 1900, now - & gt; Tm_mon + 1, now - & gt; Tm_mday);
Sprintf (timestr, "02 02 02 % d: % d: % d", now - & gt; Tm_hour, now - & gt; Tm_min, now - & gt; Tm_sec);
Sprintf (MSS, "% 3 d", TB. Millitm);
Printf (" % s % s. % s % s ", datestr, timestr, MSS, logstr);
Flog=fopen (logfilename1, "a");
If (NULL! Flog)={
Fprintf (flog, "% s % s. % s % s", datestr, timestr, MSS, logstr);
If (ftell (flog) & gt; MAXLOGSIZE) {
The fclose (flog);
If (rename (logfilename1 logfilename2)) {
Remove (logfilename2);
Rename (logfilename1 logfilename2);
}
} else {
The fclose (flog);
}
}
}
Void the Log (const char * pszFmt,... ) {
Va_list argp;

The Lock (& amp; Cs_log);
Va_start (argp, pszFmt);
LogV (pszFmt argp);
Va_end (argp);
Unlock (& amp; Cs_log);
}
//the Log}
# define ASIZE 200
# define BSIZE 240
# define CSIZE 2
Char Abuf [ASIZE];
Char Cbuf [CSIZE];
CRITICAL_SECTION cs_HEX;
CRITICAL_SECTION cs_BBB;
Struct FIFO_BUFFER {
Int the head;
Int tail;
Int size;
Char data [BSIZE];
} BBB;
Int No_Loop=0;
Void HexDump) (int cn, char * buf, int len) {
int i,j,k;
Char binstr [80].

The Lock (& amp; Cs_HEX);
for (i=0; iIf (0==16) (I %) {
Sprintf (binstr, "% 3 d % 4 x -", cn, I);
Sprintf (binstr, "% s % 02 x", binstr, buf (unsigned char) [I]); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related