Click here to Skip to main content
16,013,548 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Exception-Safe Copy Assignment Pin
CPallini27-Mar-08 4:32
mveCPallini27-Mar-08 4:32 
GeneralRe: Exception-Safe Copy Assignment Pin
George_George27-Mar-08 4:40
George_George27-Mar-08 4:40 
GeneralRe: Exception-Safe Copy Assignment Pin
led mike27-Mar-08 4:45
led mike27-Mar-08 4:45 
GeneralRe: Exception-Safe Copy Assignment Pin
peterchen27-Mar-08 5:51
peterchen27-Mar-08 5:51 
GeneralRe: Exception-Safe Copy Assignment Pin
George_George27-Mar-08 17:39
George_George27-Mar-08 17:39 
GeneralRe: Exception-Safe Copy Assignment Pin
led mike28-Mar-08 4:41
led mike28-Mar-08 4:41 
GeneralRe: Exception-Safe Copy Assignment Pin
George_George28-Mar-08 5:07
George_George28-Mar-08 5:07 
GeneralRe: Exception-Safe Copy Assignment Pin
led mike28-Mar-08 6:01
led mike28-Mar-08 6:01 
George_George wrote:
If there is exception thrown in assignment operator


Then don't do one. If you can't perform the activities required in an assignment operation without the possibility of an exception, then override the assignment operator as private to keep anyone from using it and implement the feature as a method. The method name should be descriptive like "Copy" or "SafeCopy" or something and would then be appropriate to perform any sort of operation you want with documentation of the pre/post conditions and alternate outcomes. In rare and unavoidable cases it is even appropriate for the documentation to state that in the case of an exception the state of the object is unknown.

When a user sees the method name "SafeCopy" he should be interested in reading the documentation to discover exactly what that means. This is not true for an assignment operator which carries an implicit contractual meaning.


led mike

GeneralRe: Exception-Safe Copy Assignment Pin
George_George28-Mar-08 21:13
George_George28-Mar-08 21:13 
QuestionRe: Exception-Safe Copy Assignment Pin
CPallini27-Mar-08 4:49
mveCPallini27-Mar-08 4:49 
GeneralRe: Exception-Safe Copy Assignment Pin
George_George27-Mar-08 17:54
George_George27-Mar-08 17:54 
GeneralRe: Exception-Safe Copy Assignment Pin
CPallini27-Mar-08 22:17
mveCPallini27-Mar-08 22:17 
GeneralRe: Exception-Safe Copy Assignment Pin
George_George27-Mar-08 23:23
George_George27-Mar-08 23:23 
GeneralRe: Exception-Safe Copy Assignment Pin
CPallini27-Mar-08 23:41
mveCPallini27-Mar-08 23:41 
GeneralRe: Exception-Safe Copy Assignment Pin
George_George27-Mar-08 23:50
George_George27-Mar-08 23:50 
GeneralRe: Exception-Safe Copy Assignment Pin
led mike27-Mar-08 4:41
led mike27-Mar-08 4:41 
GeneralRe: Exception-Safe Copy Assignment Pin
George_George27-Mar-08 4:43
George_George27-Mar-08 4:43 
GeneralRe: Exception-Safe Copy Assignment Pin
led mike27-Mar-08 4:47
led mike27-Mar-08 4:47 
GeneralRe: Exception-Safe Copy Assignment Pin
CPallini27-Mar-08 4:56
mveCPallini27-Mar-08 4:56 
GeneralRe: Exception-Safe Copy Assignment Pin
George_George27-Mar-08 17:52
George_George27-Mar-08 17:52 
QuestionRe: Exception-Safe Copy Assignment Pin
CPallini27-Mar-08 4:45
mveCPallini27-Mar-08 4:45 
GeneralRe: Exception-Safe Copy Assignment Pin
led mike27-Mar-08 4:50
led mike27-Mar-08 4:50 
GeneralRe: Exception-Safe Copy Assignment Pin
CPallini27-Mar-08 4:58
mveCPallini27-Mar-08 4:58 
GeneralRe: Exception-Safe Copy Assignment Pin
led mike27-Mar-08 5:06
led mike27-Mar-08 5:06 
QuestionRe: Exception-Safe Copy Assignment Pin
CPallini27-Mar-08 5:15
mveCPallini27-Mar-08 5:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.