Home > Software engineering >  MFC under how to make the use of the NEW is not thrown exception how to implement
MFC under how to make the use of the NEW is not thrown exception how to implement

Time:09-23

General new memory allocation failure are abnormal, how to make he does not throw exceptions, judging by the return value

CodePudding user response:

By the try... Try the catch ()

CodePudding user response:

New (STD: : nothrow)

CodePudding user response:

reference 1st floor VisualEleven response:
through the try... Try the catch ()

Have not thrown exception, capture meaningful???

refer to the second floor oyljerry response:
new (STD: : nothrow)

Did you try ah, so many flowers are not white hang???????

CodePudding user response:

http://blog.csdn.net/jia_xiaoxin/article/details/3347904
Look at this, hope to help you ~

CodePudding user response:

The first is to determine the reason why you throw an exception, because not enough memory? Or because other

CodePudding user response:

reference 5 floor HDT reply:
first is to determine the reason why you throw an exception, because not enough memory? Or because other

See the problem?

CodePudding user response:

refer to 6th floor bug1190 response:
Quote: refer to fifth floor HDT response:

The first is to determine the reason why you throw an exception, because not enough memory? Or because other

See the problem?

What you said is not clear, the code

CodePudding user response:

refer to 7th floor HDT response:
Quote: refer to the sixth floor bug1190 response:

Quote: refer to fifth floor HDT response:

The first is to determine the reason why you throw an exception, because not enough memory? Or because other

See the problem?

What you said is not clear, the code


Is MFC, I don't want TRY to CATCH to surround the new,,, I don't throw exceptions to the new, the results back, let me know if it have to do is make a mistake, other myself in the new processing outside, how to implement

CodePudding user response:

Simple judgment whether to NULL

CodePudding user response:

references 9/f, HDT response:
simple judgment whether it is ok to NULL

Premise is to make the NEW failure not to let it throw exceptions, and then to determine whether such is NULL, or haven't waiting for you to judge, abnormal out first, isn't it just hung up the program, it is futile,,,, just now I tried, it is such a

Key is actually generated MFC can't deal with it when the class object, other cases can be,,, do NEW a MFC class object, must use the TRY CATCH,,

CodePudding user response:

references to the tenth floor bug1190 response:
Quote: HDT, 9/f, reference response:

It is ok to simply determine whether NULL

Premise is to make the NEW failure not to let it throw exceptions, and then to determine whether such is NULL, or haven't waiting for you to judge, abnormal out first, isn't it just hung up the program, it is futile,,,, just now I tried, it is such a

Key is actually generated MFC can't deal with it when the class object, other cases can be,,, do NEW a MFC class object, must use the TRY CATCH,,


So I let you get on the code

CodePudding user response:

Roughly two operations, the new one is a piece of memory, and then calls the constructor, the two generally should not be abnormal, (unless memory),

CodePudding user response:

refer to 12 floor HDT reply:
new roughly two operations, one is a piece of memory, and then calls the constructor, the two generally should not be abnormal, (unless memory),

To explain to you is boring, and what should not be abnormal, is a programmer knows you also the spectrum in the repeat, not tired,
I now is to solve "the one thousand out of the abnormal situation" code, understand? On the code, and you want me,,, have no language,,,

CodePudding user response:

refer to the eighth floor bug1190 response:
is MFC, I don't want to let the TRY CATCH to surround the new,,, I don't throw exceptions to the new, the results back, let me know if it have to do is make a mistake, other myself in the new processing outside, how to implement

That can't achieve, the new has a problem, how much data area it was new

CodePudding user response:

reference 13 floor bug1190 reply:
Quote: refer to 12 floor HDT reply:

Roughly two operations, the new one is a piece of memory, and then calls the constructor, the two generally should not be abnormal, (unless memory),

To explain to you is boring, and what should not be abnormal, is a programmer knows you also the spectrum in the repeat, not tired,
I now is to solve "the one thousand out of the abnormal situation" code, understand? Code, you want me,,, have no language,,,

You so to speak, just like a patient, the doctor said "I'm sick," the doctor ask you which suffered, you will only answer "I'm sick"

CodePudding user response:

The new role is first allocated memory, the second is on the allocated memory calls the constructor, as a result of new exception to operator but is out of memory and the constructor statement
Out of memory problem, can only be your new object constructor there are some operating problems,
Why you should find new failure

CodePudding user response:

http://technet.microsoft.com/zh-cn/aa298584

CodePudding user response:

reference 16 floor King_hhuang response:
new role is first allocated memory, the second is on the allocated memory calls the constructor, as a result of new exception to operator but is out of memory and constructor statement
Out of memory problem, can only be your new object constructor there are some operating problems,
Why you should find new failure


Yourself with the two kinds of circumstances, but turn a blind eye to the first case, and I have to solve is the first case, as for the second case, I have given you remind of enough -- -- -- -- -- -- -- -- I am under the MFC, and using SET_NEW_HANDLE is actually a method, but I don't think that trouble

CodePudding user response:

Try
{}
The catch (STD: : bad_alloc & amp; E)
{}

To catch with bad_alloc can return,

CodePudding user response:

refer to the 18th floor bug1190 response:
Quote: refer to the 16th floor King_hhuang response:

The new role is first allocated memory, the second is on the allocated memory calls the constructor, as a result of new exception to operator but is out of memory and the constructor statement
Out of memory problem, can only be your new object constructor there are some operating problems,
Why you should find new failure


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related