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. can anybody tell me What happens if an exception is throws from an, object's constructor and object's destructor?

can anybody tell me What happens if an exception is throws from an, object's constructor and object's destructor?

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 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 Offline
    P Offline
    philiptabraham
    wrote on last edited by
    #1

    can anybody tell me What happens if an exception is throws from an, object's constructor and object's destructor? thanks in dvance

    C P 2 Replies Last reply
    0
    • P philiptabraham

      can anybody tell me What happens if an exception is throws from an, object's constructor and object's destructor? thanks in dvance

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Ask George_George: he made a extensive study about... :-D Seriously, IMHO opinion, the object consumer has to care about of that possibility exactly like it does with standard method thrown exceptions. A difference maybe the fact that object construction/destruction sometimes happens implicitly (and is somehow hidden to the consumer itself). :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      [my articles]

      1 Reply Last reply
      0
      • P philiptabraham

        can anybody tell me What happens if an exception is throws from an, object's constructor and object's destructor? thanks in dvance

        P Offline
        P Offline
        peterchen
        wrote on last edited by
        #3

        [1] Constructor The object will never be created. Destructor is NOT called. If you allocated ressources before the exception is thrown, they are NOT freed. [2] Destructors Technically, the object is left in an undefined state. Likely, Accessing it afterwards will fail, and resources may leak. Practically, destructors should NEVER throw. It violates even the most basic exception safety guarantee: that objects remain destructable, no matter what. For lots of more information, try the GOTW columns[^] that deal with exceptions

        We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
        My first real C# project | Linkify!| FoldWithUs! | sighist

        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