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. General Programming
  3. C / C++ / MFC
  4. Stroustrup's RAII code

Stroustrup's RAII code

Scheduled Pinned Locked Moved C / C++ / MFC
c++comquestion
4 Posts 4 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.
  • E Offline
    E Offline
    elelont2
    wrote on last edited by
    #1

    I am watching a video where B. Stroustrup talks about c++ - link-> (31:23) ()[^] I have trouble understanding the RAII slide: http://www.upload.ee/image/4090006/raii.png 1) Why doesn't he catch the exception? 2) I keep reading that when constructor throws, the destructor of an object is never called. Regards

    L C J 3 Replies Last reply
    0
    • E elelont2

      I am watching a video where B. Stroustrup talks about c++ - link-> (31:23) ()[^] I have trouble understanding the RAII slide: http://www.upload.ee/image/4090006/raii.png 1) Why doesn't he catch the exception? 2) I keep reading that when constructor throws, the destructor of an object is never called. Regards

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2
      1. In a real program he most likely catches it in the code that tries to create the object. 2) If the constructor throws an exception then the object is not created so there is no destructor to call. 3) Why not ask Stroustrup?
      1 Reply Last reply
      0
      • E elelont2

        I am watching a video where B. Stroustrup talks about c++ - link-> (31:23) ()[^] I have trouble understanding the RAII slide: http://www.upload.ee/image/4090006/raii.png 1) Why doesn't he catch the exception? 2) I keep reading that when constructor throws, the destructor of an object is never called. Regards

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3
        1. Why should he? 2) That's fine: if the constructor cannot open the file then the destructor fclose call doesn't make sense.

        Veni, vidi, vici.

        1 Reply Last reply
        0
        • E elelont2

          I am watching a video where B. Stroustrup talks about c++ - link-> (31:23) ()[^] I have trouble understanding the RAII slide: http://www.upload.ee/image/4090006/raii.png 1) Why doesn't he catch the exception? 2) I keep reading that when constructor throws, the destructor of an object is never called. Regards

          J Offline
          J Offline
          Joe Woodbury
          wrote on last edited by
          #4

          Why doesn't he use the handle? It's for illustration purposes only.

          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