Click here to Skip to main content
15,889,909 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: GetUserName() return "SYSTEM" FOR SYSTEM PROCESS Pin
Mark Salsbery21-Dec-07 7:44
Mark Salsbery21-Dec-07 7:44 
GeneralExtra bytes between struct elements spoiling match between structs and binary file formats: cure found Pin
Anthony Appleyard21-Dec-07 1:59
Anthony Appleyard21-Dec-07 1:59 
GeneralRe: Extra bytes between struct elements spoiling match between structs and binary file formats: cure found Pin
Matthew Faithfull21-Dec-07 2:13
Matthew Faithfull21-Dec-07 2:13 
JokeIndeed... Pin
CPallini21-Dec-07 2:52
mveCPallini21-Dec-07 2:52 
JokeRe: Indeed... Pin
Matthew Faithfull21-Dec-07 3:04
Matthew Faithfull21-Dec-07 3:04 
GeneralRe: Indeed... Pin
CPallini21-Dec-07 3:15
mveCPallini21-Dec-07 3:15 
GeneralRe: Extra bytes between struct elements spoiling match between structs and binary file formats: cure found Pin
Mark Salsbery21-Dec-07 8:14
Mark Salsbery21-Dec-07 8:14 
Questionis such exception handling approach good? Pin
George_George21-Dec-07 1:42
George_George21-Dec-07 1:42 
Hello everyone,


Suppose I have some objects created on local function stack (not on heap). And I allocate and free all the related resources in the constructor and destructor (e.g. memory and file handles). And I do not implement explicit exception handling code in the function for resource free purpose, and simply rely on destructor to free resources if exception occurs, that is,

1. when exception occurs and the exception triggers us to go out of current function stack to the caller to find exception handlers;
2. since objects are allocated on local stack, when exception triggers us to go out of current stack to its caller to find exception handler, the lifecycle of local objects on local stack will expire, and its related destructor will be invoked and free resources.

Pseudo code like this,

void func()
{
      Class1 inst1;
      Class2 inst2;

      ... // some operations

      return;
}


Does above code always safe? Are there any potential risks to leak resources?


thanks in advance,
George
AnswerRe: is such exception handling approach good? Pin
Matthew Faithfull21-Dec-07 2:05
Matthew Faithfull21-Dec-07 2:05 
QuestionThread using COleDispatchDriver always causes exception on second execution Pin
Streifenhoernchen21-Dec-07 1:42
Streifenhoernchen21-Dec-07 1:42 
GeneralRe: Thread using COleDispatchDriver always causes exception on second execution Pin
Nathan Holt at EMOM21-Dec-07 7:43
Nathan Holt at EMOM21-Dec-07 7:43 
GeneralSubclassing (using MFC) a wndow under explorer process Pin
Nishad S21-Dec-07 1:38
Nishad S21-Dec-07 1:38 
QuestionReference are always lvalue? Pin
George_George21-Dec-07 1:11
George_George21-Dec-07 1:11 
AnswerRe: Reference are always lvalue? Pin
Budric B.21-Dec-07 5:09
Budric B.21-Dec-07 5:09 
GeneralRe: Reference are always lvalue? Pin
George_George21-Dec-07 19:16
George_George21-Dec-07 19:16 
Questionhow to get the number of lines shown in editbox Pin
rajneshmalik21-Dec-07 1:06
rajneshmalik21-Dec-07 1:06 
AnswerRe: how to get the number of lines shown in editbox Pin
CPallini21-Dec-07 3:05
mveCPallini21-Dec-07 3:05 
GeneralDatashowing problem want to get rid of from if-else statement Pin
Y_Kaushik20-Dec-07 23:53
Y_Kaushik20-Dec-07 23:53 
GeneralRe: Datashowing problem want to get rid of from if-else statement Pin
Hamid_RT21-Dec-07 0:02
Hamid_RT21-Dec-07 0:02 
GeneralRe: Datashowing problem want to get rid of from if-else statement Pin
Cedric Moonen21-Dec-07 0:13
Cedric Moonen21-Dec-07 0:13 
GeneralRe: Datashowing problem want to get rid of from if-else statement Pin
Cedric Moonen21-Dec-07 0:11
Cedric Moonen21-Dec-07 0:11 
GeneralRe: Datashowing problem want to get rid of from if-else statement Pin
Matthew Faithfull21-Dec-07 0:11
Matthew Faithfull21-Dec-07 0:11 
GeneralRe: Datashowing problem want to get rid of from if-else statement Pin
Y_Kaushik21-Dec-07 19:08
Y_Kaushik21-Dec-07 19:08 
GeneralDynamically providing version information to a exe Pin
neha.agarwal2720-Dec-07 22:50
neha.agarwal2720-Dec-07 22:50 
GeneralRe: Dynamically providing version information to a exe Pin
jhwurmbach20-Dec-07 23:08
jhwurmbach20-Dec-07 23:08 

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.