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. Layers and exceptions

Layers and exceptions

Scheduled Pinned Locked Moved The Lounge
designbusinesshelpquestion
47 Posts 23 Posters 0 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.
  • P PIEBALDconsult

    The contents of the trace will depend on whether or not it's a debug build. But I assume that you're debugging a debug build.

    L Offline
    L Offline
    Lowell Boggs
    wrote on last edited by
    #41

    Yep, debug builds for sure.

    1 Reply Last reply
    0
    • P PIEBALDconsult

      Here's a simple example. An Exception could be thrown (or passed along) by any of the methods, all will be caught and displayed by the Main.

      namespace Template
      {
      public partial class Template
      {
      private static int
      Div
      (
      string Op1
      ,
      string Op2
      )
      {
      return ( Div ( int.Parse ( Op1 ) , int.Parse ( Op2 ) ) ) ;
      }

          private static int
          Div
          (
              int Op1
          ,
              int Op2
          )
          {
              return ( Op1 / Op2 ) ;
          }
      
          \[System.STAThreadAttribute\]
          public static int
          Main
          (
              string\[\] args
          )
          {
              int result = 0 ;
      
              try
              {
                  System.Console.WriteLine ( Div ( args \[ 0 \] , args \[ 1 \] ) ) ;
              }
              catch ( System.Exception err )
              {
                  System.Console.WriteLine ( err.Message ) ;
                  System.Console.WriteLine ( err.TargetSite ) ;
                  System.Console.WriteLine ( err.StackTrace ) ;
              }
      
              return ( result ) ;
          }
      }
      

      }

      In this run Main encounters an error.

      C:\>StackTest
      Index was outside the bounds of the array.
      Int32 Main(System.String[])
      at Template.Template.Main(String[] args)

      In this run the Exception came from deep in the belly of .net

      C:\>StackTest a b
      Input string was not in a correct format.
      Void StringToNumber(System.String, System.Globalization.NumberStyles, NumberBuffer ByRef, System.Globalization.NumberFormatInfo, Boolean)
      at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
      at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
      at System.Int32.Parse(String s)
      at Template.Template.Div(String Op1, String Op2)
      at Template.Template.Main(String[] args)

      In this run the integer divide threw the Exception

      C:\>StackTest 1 0
      Attempted to divide by zero.
      Int32 Div(Int32, Int32)
      at Template.Template.Div(Int32 Op1, Int32 Op2)
      at Template.Template.Div(String Op1, String Op2)
      at Template.Template.Main(String[] args)

      L Offline
      L Offline
      Lowell Boggs
      wrote on last edited by
      #42

      Yeah - that would be nice. I wonder if there is a way to get VC++ 2003 to dump the processing of the thrown exception so that by the time we get to the breakpoint on the in the catch handler, we can at least see the trace back to the throw point. I'll see if there is something I'm missing in output window from the debugger -- but I've looked before and couldn't find it. Of course, my wife says I couldn't find my nose on my face. I'll spend a little more time checking. Wish me luck.

      P 1 Reply Last reply
      0
      • L Lowell Boggs

        Yeah - that would be nice. I wonder if there is a way to get VC++ 2003 to dump the processing of the thrown exception so that by the time we get to the breakpoint on the in the catch handler, we can at least see the trace back to the throw point. I'll see if there is something I'm missing in output window from the debugger -- but I've looked before and couldn't find it. Of course, my wife says I couldn't find my nose on my face. I'll spend a little more time checking. Wish me luck.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #43

        (I think I know where you'd like to find your nose.) Ahem, ahem... so anyway... If it's Managed C++ you should be fine (I guess) as it's a .net issue, not a language issue. In .net at least, when the Exception is instantiated it's populated with the stacktrace at that point. But it does appear that in a standard release build, the stack trace is not fully populated.

        1 Reply Last reply
        0
        • L Lowell Boggs

          I agree completely that there is no magic solution. As for my comments about exceptions slowing things down, I have measured it myself with several compilers. Merely compiling with exceptions turned on causes between 5 and 25% slowdown in algorithms that access large amounts of memory to, say, exhaustively search a large in-memory data set. I do understand that this is a rare kind of program to be writing, but everything has its place. Sometimes exceptions really don't matter for performance -- for example if you are doing a lot of system calls. None the less, I really wish they hadn't been added to the language. Other people are getting to force their annoyances on me as a developer, and they don't don't even have to write good documentation explaining the exceptions. This could also be true with error codes -- but they are a lot easier to debug than exceptions given the limitations of the tools available to me. We'll just have to agree to disagree. Peace, Lowell

          N Offline
          N Offline
          niko78
          wrote on last edited by
          #44

          Hi: Error codes are obsolete and they must be elimated from new software develoment. Error code are ignored and all methods that invoque function with error codes must return error codes, this sucks !! Exception must be cached on BR and loged if you want. Thanks

          La entrada es gratis, la salida vemos....

          1 Reply Last reply
          0
          • L Lowell Boggs

            I agree completely that there is no magic solution. As for my comments about exceptions slowing things down, I have measured it myself with several compilers. Merely compiling with exceptions turned on causes between 5 and 25% slowdown in algorithms that access large amounts of memory to, say, exhaustively search a large in-memory data set. I do understand that this is a rare kind of program to be writing, but everything has its place. Sometimes exceptions really don't matter for performance -- for example if you are doing a lot of system calls. None the less, I really wish they hadn't been added to the language. Other people are getting to force their annoyances on me as a developer, and they don't don't even have to write good documentation explaining the exceptions. This could also be true with error codes -- but they are a lot easier to debug than exceptions given the limitations of the tools available to me. We'll just have to agree to disagree. Peace, Lowell

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #45

            Lowell Boggs wrote:

            causes between 5 and 25% slowdown

            Then you should investigate what the problem is, there's no reason your code should be throwing that many Exceptions.

            S L 2 Replies Last reply
            0
            • P PIEBALDconsult

              Lowell Boggs wrote:

              causes between 5 and 25% slowdown

              Then you should investigate what the problem is, there's no reason your code should be throwing that many Exceptions.

              S Offline
              S Offline
              S B
              wrote on last edited by
              #46

              The point Lowell is trying to make is that simply compiling with exceptions enabled in C++ causes a 5% to 25% performance hit due to the overhead in function calls, stack manipulation and the inability for the compiler to optimize as well as it can without exceptions enabled. Even if not a single exception was thrown in the entire application, the compiler still has to allow for the possibility that one could be, and this makes it's job much harder and results in a loss of optimizations. Personally I think exceptions have their place, sometimes things beyond our knowledge or control occur, eg a memory access violation where the immediate calling code has no idea about what it should do to handle this kind of error or if the operation that failed is important enough to be fatal to the application. If it's just logging a trace log then who cares? If it's writing a bank account transfer then it's a big deal. This exceptional situation needs to be handled at a higher level where the intention of the code is apparent. I don't think undocumented exceptions should be thrown out of libraries though. Libraries should have a strict interface and exceptions should be well documented for all error conditions.

              1 Reply Last reply
              0
              • P PIEBALDconsult

                Lowell Boggs wrote:

                causes between 5 and 25% slowdown

                Then you should investigate what the problem is, there's no reason your code should be throwing that many Exceptions.

                L Offline
                L Offline
                Lowell Boggs
                wrote on last edited by
                #47

                The code was not throwing ANY exceptions. The slowdown comes from using the C++ compiler options that enabled exceptions. In the microsoft VC++ compiler, exceptions are disabled by default and you have to use an option to turn them on. However, the point is mute at this point in time -- in order to use the STL on many compilers, you have to compile with exception support. Still, you want a function to be as fast as can be it should be declare in such a way that it does not support exceptions. This may not apply to interpretive languages which are fundamentally slower than compiled languages anyway.

                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