Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. A question of indentation!

A question of indentation!

Scheduled Pinned Locked Moved The Lounge
questionc++helptutorial
81 Posts 23 Posters 64 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Eddie Velasquez

    Daniel Turini wrote: That's why exception handling was invented. Try throwing exceptions instead of nesting if's. Not necessarilly. Exceptions should only be used for reporting "exceptional" conditions and not all function returns mean and exceptional condition. e.g. In some cases an end-of-file is a normal situation, but if reading a header of a structured file it means that the file is corrupt and should raise an exception.


    Eddie Velasquez: A Squeezed Devil
    Checkout General Guidelines for C# Class Implementation

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #20

    An exception does not necessarily mean an error. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

    E 1 Reply Last reply
    0
    • N Nish Nishant

      Daniel Turini wrote: That's why exception handling was invented. Try throwing exceptions instead of nesting if's. Cool! I never thought of that! I just don't know much about exception handling though. What's this PGPException thing? Nish


      Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #21

      Try/Thow/catch ( and finally in C#, dunno about C++ ) are the obvious way to deal with your situation. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

      N 1 Reply Last reply
      0
      • E Eddie Velasquez

        Nish - Native CPian wrote: I can't do that. Since I need to do some cleaning up as well That's why you should wrap up the API in C++ classes and let destructors take care of the cleanup.


        Eddie Velasquez: A Squeezed Devil
        Checkout General Guidelines for C# Class Implementation

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #22

        Eddie Velasquez wrote: That's why you should wrap up the API in C++ classes and let destructors take care of the cleanup. Yeah, I gotta do that. I really must! I am not a naturally OOPish guy, you know! Nish :-)


        Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

        E 1 Reply Last reply
        0
        • E Eddie Velasquez

          Daniel Turini wrote: That's why exception handling was invented. Try throwing exceptions instead of nesting if's. Not necessarilly. Exceptions should only be used for reporting "exceptional" conditions and not all function returns mean and exceptional condition. e.g. In some cases an end-of-file is a normal situation, but if reading a header of a structured file it means that the file is corrupt and should raise an exception.


          Eddie Velasquez: A Squeezed Devil
          Checkout General Guidelines for C# Class Implementation

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #23

          Well, the indentation of this thread has gone totally haywire. All my replies are appearing under the wrong persons :( Nish


          Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

          1 Reply Last reply
          0
          • D Daniel Turini

            I thought that in PGP SDK a return value of false indicates an error condition. Crivo Automated Credit Assessment

            E Offline
            E Offline
            Eddie Velasquez
            wrote on last edited by
            #24

            Daniel Turini wrote: thought that in PGP SDK a return value of false indicates an error condition. Well, I was talking in a general sense and didn't realize you were referring to the PGP SDK in particular. My bad.


            Eddie Velasquez: A Squeezed Devil
            Checkout General Guidelines for C# Class Implementation

            N 1 Reply Last reply
            0
            • C Christian Graus

              Try/Thow/catch ( and finally in C#, dunno about C++ ) are the obvious way to deal with your situation. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #25

              Christian Graus wrote: Try/Thow/catch ( and finally in C#, dunno about C++ ) are the obvious way to deal with your situation. I don't even know how to implement exceptions :-( Might have to do some reading Actually after reading all the suggestions, I liked peterchens do{} while(0) idea :-) Nish


              Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

              J 1 Reply Last reply
              0
              • T Tomasz Sowinski

                Nish - Native CPian wrote: I am not supposed to call call-n unless call-n-1 returns true! Geez, Nish, you're disappointing me again :-D How can you think about earning almost $90K without basic C++ knowledge? Don't you know how logical operators work? call-n isn't going to be called when call-n-1 returns false. Tomasz Sowinski -- http://www.shooltz.com

                - It's for protection
                - Protection from what? Zee Germans?

                N Offline
                N Offline
                Nish Nishant
                wrote on last edited by
                #26

                Tomasz Sowinski wrote: Geez, Nish, you're disappointing me again How can you think about earning almost $90K without basic C++ knowledge? Don't you know how logical operators work? call-n isn't going to be called when call-n-1 returns false. Nope! Not with PGP. When I wrote the original post I simplified things. PGP calls return a PGPError struct and I have to call IsPGPError() on it to find out whether it's an error :-( Not a true/false thing at all!!! Nish


                Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                T 1 Reply Last reply
                0
                • C Christian Graus

                  An exception does not necessarily mean an error. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

                  E Offline
                  E Offline
                  Eddie Velasquez
                  wrote on last edited by
                  #27

                  Christian Graus wrote: An exception does not necessarily mean an error. An exception should always indicate an error... that's why they're called "exceptions"... because they're exceptional. :) Or did I miss something in your post?


                  Eddie Velasquez: A Squeezed Devil
                  Checkout General Guidelines for C# Class Implementation

                  N C 2 Replies Last reply
                  0
                  • N Nish Nishant

                    Tomasz Sowinski wrote: Geez, Nish, you're disappointing me again How can you think about earning almost $90K without basic C++ knowledge? Don't you know how logical operators work? call-n isn't going to be called when call-n-1 returns false. Nope! Not with PGP. When I wrote the original post I simplified things. PGP calls return a PGPError struct and I have to call IsPGPError() on it to find out whether it's an error :-( Not a true/false thing at all!!! Nish


                    Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                    T Offline
                    T Offline
                    Tomasz Sowinski
                    wrote on last edited by
                    #28

                    Well, it seems that you need some kind of object wrapper over PGPError. The object could convert that to true/false or even throw some exception. Tomasz Sowinski -- http://www.shooltz.com

                    - It's for protection
                    - Protection from what? Zee Germans?

                    N 1 Reply Last reply
                    0
                    • E Eddie Velasquez

                      Daniel Turini wrote: thought that in PGP SDK a return value of false indicates an error condition. Well, I was talking in a general sense and didn't realize you were referring to the PGP SDK in particular. My bad.


                      Eddie Velasquez: A Squeezed Devil
                      Checkout General Guidelines for C# Class Implementation

                      N Offline
                      N Offline
                      Nish Nishant
                      wrote on last edited by
                      #29

                      Eddie Velasquez wrote: Well, I was talking in a general sense and didn't realize you were referring to the PGP SDK in particular. My bad. PGP calls return a PGPError and you need to call IsPGPError(...) on it to figure out whether it was an error or not. Some cases you actually get an error and it's not really an error overall! Like some encryption algorithms won't work when it's an RSA key but you are supposed to ignore that since it won't cause any problem Nish


                      Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                      J 1 Reply Last reply
                      0
                      • E Eddie Velasquez

                        Christian Graus wrote: An exception does not necessarily mean an error. An exception should always indicate an error... that's why they're called "exceptions"... because they're exceptional. :) Or did I miss something in your post?


                        Eddie Velasquez: A Squeezed Devil
                        Checkout General Guidelines for C# Class Implementation

                        N Offline
                        N Offline
                        Nish Nishant
                        wrote on last edited by
                        #30

                        Eddie Velasquez wrote: An exception should always indicate an error... That's what I also thought. But PGP errors are often not errors. I have explained in one of the mis-placed posts here. I don't wanna re-type it :-) The indendation of this thread is now worse than any indentation I could have produced :-) Nish


                        Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                        E 1 Reply Last reply
                        0
                        • N Nish Nishant

                          Eddie Velasquez wrote: That's why you should wrap up the API in C++ classes and let destructors take care of the cleanup. Yeah, I gotta do that. I really must! I am not a naturally OOPish guy, you know! Nish :-)


                          Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                          E Offline
                          E Offline
                          Eddie Velasquez
                          wrote on last edited by
                          #31

                          (Using my best Yoda voice...) Ummm. Strong in the force you are... but OOP you must.;)


                          Eddie Velasquez: A Squeezed Devil
                          Checkout General Guidelines for C# Class Implementation

                          N 1 Reply Last reply
                          0
                          • T Tomasz Sowinski

                            Well, it seems that you need some kind of object wrapper over PGPError. The object could convert that to true/false or even throw some exception. Tomasz Sowinski -- http://www.shooltz.com

                            - It's for protection
                            - Protection from what? Zee Germans?

                            N Offline
                            N Offline
                            Nish Nishant
                            wrote on last edited by
                            #32

                            Tomasz Sowinski wrote: Well, it seems that you need some kind of object wrapper over PGPError. The object could convert that to true/false or even throw some exception Shucks! It always comes down to the basics and theory. If my OOP theory was strong enough I'd not have run into this situation :-( Nish


                            Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                            T J 2 Replies Last reply
                            0
                            • N Nish Nishant

                              Daniel Turini wrote: That's why exception handling was invented. Try throwing exceptions instead of nesting if's. Cool! I never thought of that! I just don't know much about exception handling though. What's this PGPException thing? Nish


                              Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                              D Offline
                              D Offline
                              Daniel Turini
                              wrote on last edited by
                              #33

                              Nish - Native CPian wrote: What's this PGPException thing? A class you'd create to handle exceptions from PGP SDK. The best exception handling class I saw for an API is CWin32Error. Probably you don't need something so complicated, but some of Jadhav's ideas are pretty good and simple to implement. Crivo Automated Credit Assessment

                              N 1 Reply Last reply
                              0
                              • D Daniel Turini

                                Nish - Native CPian wrote: What's this PGPException thing? A class you'd create to handle exceptions from PGP SDK. The best exception handling class I saw for an API is CWin32Error. Probably you don't need something so complicated, but some of Jadhav's ideas are pretty good and simple to implement. Crivo Automated Credit Assessment

                                N Offline
                                N Offline
                                Nish Nishant
                                wrote on last edited by
                                #34

                                Daniel Turini wrote: A class you'd create to handle exceptions from PGP SDK. The best exception handling class I saw for an API is CWin32Error. Probably you don't need something so complicated, but some of Jadhav's ideas are pretty good and simple to implement. Thanks! I'll look it up. Nish :-)


                                Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                                1 Reply Last reply
                                0
                                • N Nish Nishant

                                  Tomasz Sowinski wrote: Well, it seems that you need some kind of object wrapper over PGPError. The object could convert that to true/false or even throw some exception Shucks! It always comes down to the basics and theory. If my OOP theory was strong enough I'd not have run into this situation :-( Nish


                                  Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                                  T Offline
                                  T Offline
                                  Tomasz Sowinski
                                  wrote on last edited by
                                  #35

                                  Post more code - especially, how PGPError is returned and when it means an error. Tomasz Sowinski -- http://www.shooltz.com

                                  - It's for protection
                                  - Protection from what? Zee Germans?

                                  N 1 Reply Last reply
                                  0
                                  • N Nish Nishant

                                    Eddie Velasquez wrote: An exception should always indicate an error... That's what I also thought. But PGP errors are often not errors. I have explained in one of the mis-placed posts here. I don't wanna re-type it :-) The indendation of this thread is now worse than any indentation I could have produced :-) Nish


                                    Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                                    E Offline
                                    E Offline
                                    Eddie Velasquez
                                    wrote on last edited by
                                    #36

                                    Nish - Native CPian wrote: That's what I also thought. But PGP errors are often not errors. If a PGP error isn't a "real" error (informational return value) then it shouldn't raise an exception or you can catch the exception and just ignore it.


                                    Eddie Velasquez: A Squeezed Devil
                                    Checkout General Guidelines for C# Class Implementation

                                    1 Reply Last reply
                                    0
                                    • E Eddie Velasquez

                                      Christian Graus wrote: An exception does not necessarily mean an error. An exception should always indicate an error... that's why they're called "exceptions"... because they're exceptional. :) Or did I miss something in your post?


                                      Eddie Velasquez: A Squeezed Devil
                                      Checkout General Guidelines for C# Class Implementation

                                      C Offline
                                      C Offline
                                      Christian Graus
                                      wrote on last edited by
                                      #37

                                      To quote Stroustrup: The Exception handling mechanism is a nonlocal control structure based on stack unwinding that can be seen as an alternative return mechanism. There are therefore legitimate uses of exceptions that have nothing to do with errors. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

                                      J E 2 Replies Last reply
                                      0
                                      • N Nish Nishant

                                        Tomasz Sowinski wrote: if (call1() && call2() && call3() ....) That won;'t work. I am not supposed to call call-n unless call-n-1 returns true!


                                        Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                                        N Offline
                                        N Offline
                                        Navin
                                        wrote on last edited by
                                        #38

                                        Nish - Native CPian wrote: if (call1() && call2() && call3() ....) That won;'t work. I am not supposed to call call-n unless call-n-1 returns true! :confused: Why won't that work then? With C++, you have "short-circuit" evaluation - that is, if the first item in an If statement fails, the rest won't even get evaluated. For instance, I have code like this all the time (well, when I'm not using CStrings... :-D) : if(pStr != NULL && strlen(pStr) > 0) { ... } If pStr is NULL, the first condition fails, and the second condition (strlen) won't even be evaluated. No generalization is 100% true. Not even this one.

                                        N 1 Reply Last reply
                                        0
                                        • N Nish Nishant

                                          Tomasz Sowinski wrote: Well, it seems that you need some kind of object wrapper over PGPError. The object could convert that to true/false or even throw some exception Shucks! It always comes down to the basics and theory. If my OOP theory was strong enough I'd not have run into this situation :-( Nish


                                          Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

                                          J Offline
                                          J Offline
                                          James Pullicino
                                          wrote on last edited by
                                          #39

                                          Nish - Native CPian wrote: Shucks! It always comes down to the basics and theory. If my OOP theory was strong enough I'd not have run into this situation Nish, don't get discouraged. The prime motivation for most of us to learn OOP was because of these things. Don't shy away from OOP. In a few months you will be the one telling others to wrap their functions into objects. C++ Programmers do it in class Drinking In The Sun Forgot Password?

                                          N 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups