Click here to Skip to main content
16,012,508 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMany big problems... Pin
SAV5-Feb-02 22:00
SAV5-Feb-02 22:00 
GeneralRe: Many big problems... Pin
Andreas Saurwein6-Feb-02 0:44
Andreas Saurwein6-Feb-02 0:44 
QuestionHuge .bss section in DLL - why? Pin
peterchen5-Feb-02 21:39
peterchen5-Feb-02 21:39 
GeneralHandling Events with Webbrowser2 Control Pin
John Clump5-Feb-02 20:42
John Clump5-Feb-02 20:42 
GeneralRe: Handling Events with Webbrowser2 Control Pin
alex.barylski6-Feb-02 0:19
alex.barylski6-Feb-02 0:19 
GeneralAbout Exception in VC++ Pin
wabc5-Feb-02 20:29
wabc5-Feb-02 20:29 
GeneralRe: About Exception in VC++ Pin
Christian Graus5-Feb-02 20:40
protectorChristian Graus5-Feb-02 20:40 
GeneralRe: About Exception in VC++ Pin
Joaquín M López Muñoz5-Feb-02 21:29
Joaquín M López Muñoz5-Feb-02 21:29 
IMO, using try/catch all the time is a sign you don't think you've written the code properly, and is ugly. It also incurs a performance cost.

I don't agree with you here. It may look ugly (on aestethics I won't discuss), and certainly it can incur a performance penalty, but you get the following advantages by using exceptions instead of traditional error codes à la Win32 API:
  1. The performance penalty is usually only incurred when an exception actually is thrown (which is assumed to be rare). The overhead of having a try/catch block is usually negligible (between 3 and less than 10 asm instructions).
  2. Exceptions can improve performance and code size in cases where a lot of error codes have to be checked:
    // without exceptions
    if(foo1(...)!=OK){
    ...
    }
    if(foo2(...)!=OK){
    ...
    }
    ...
    if(foon(...)!=OK){
    ...
    }
    // with exceptions
    try{
      foo1(...);
      foo2(...);
      ...
      foon(...);
    }
    catch(...){
      ...
    }

  3. Exceptions are sometimes the only reasonable way to go (eg. when a ctor fails).
  4. Exceptions integrate seamlessly with the RAII (Resource Acquisition Is Initialization) idiom. They help support invariants in your classes.
  5. They can help you simplify the signatures of your functions: instead of
    BOOL getWhatever(int &whatever);
    or
    int getWhatever(); // -1 if it fails
    you can write
    int getWhatever(); // throws couldnt_do_it if it fails
I think the main problem with exceptions is that they came too late to the standard, so a huge set of code is already out there that does not use them. Also, the throw specification in function declarations is basically broken due to backwards compatibility issues. In these respects, newer exception-oriented languages like Java are in a far better position.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralRe: About Exception in VC++ Pin
Christian Graus5-Feb-02 21:41
protectorChristian Graus5-Feb-02 21:41 
GeneralRe: About Exception in VC++ Pin
Joaquín M López Muñoz5-Feb-02 21:55
Joaquín M López Muñoz5-Feb-02 21:55 
GeneralRe: About Exception in VC++ Pin
John Clump5-Feb-02 20:55
John Clump5-Feb-02 20:55 
GeneralRe: About Exception in VC++ Pin
alex.barylski5-Feb-02 21:31
alex.barylski5-Feb-02 21:31 
GeneralTricky NT Service Question Pin
Richard Ellis5-Feb-02 19:11
Richard Ellis5-Feb-02 19:11 
GeneralRe: Tricky NT Service Question Pin
Nish Nishant5-Feb-02 20:29
sitebuilderNish Nishant5-Feb-02 20:29 
GeneralRe: Tricky NT Service Question Pin
Michael Dunn5-Feb-02 20:30
sitebuilderMichael Dunn5-Feb-02 20:30 
GeneralRe: Tricky NT Service Question Pin
Andreas Saurwein6-Feb-02 0:27
Andreas Saurwein6-Feb-02 0:27 
GeneralRe: Tricky NT Service Question Pin
Richard Ellis6-Feb-02 18:57
Richard Ellis6-Feb-02 18:57 
QuestionWhat Message is issued? Pin
AnonymousBabe@usa.net5-Feb-02 16:16
AnonymousBabe@usa.net5-Feb-02 16:16 
AnswerRe: What Message is issued? Pin
Paul M Watt5-Feb-02 19:00
mentorPaul M Watt5-Feb-02 19:00 
Questionany other chinese programmer in USA ? Pin
hinasoft5-Feb-02 15:03
hinasoft5-Feb-02 15:03 
AnswerRe: any other chinese programmer in USA ? Pin
alex.barylski5-Feb-02 16:43
alex.barylski5-Feb-02 16:43 
GeneralRe: any other chinese programmer in USA ? Pin
AnonymousBabe@usa.net5-Feb-02 17:32
AnonymousBabe@usa.net5-Feb-02 17:32 
GeneralCaret and MDI View Pin
AnonymousBabe@usa.net5-Feb-02 14:15
AnonymousBabe@usa.net5-Feb-02 14:15 
GeneralSetting up CListView Properties Pin
Aaron Schaefer5-Feb-02 12:07
Aaron Schaefer5-Feb-02 12:07 
GeneralRe: Setting up CListView Properties Pin
Derek Waters5-Feb-02 12:17
Derek Waters5-Feb-02 12:17 

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.