home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / std / cplus / 1097 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  2.1 KB

  1. Path: sparky!uunet!utcsri!turing.toronto.edu!mendell
  2. Newsgroups: comp.std.c++
  3. From: mendell@turing.toronto.edu (Mark Mendell)
  4. Subject: Re: constructors and exceptions
  5. Message-ID: <1992Aug20.232503.23209@jarvis.csri.toronto.edu>
  6. Organization: IBM Toronto Lab
  7. References: <2286@devnull.mpd.tandem.com>
  8. Date: 21 Aug 92 03:25:04 GMT
  9. Lines: 40
  10.  
  11. Real working exception handling in the IBM xlC C++ compiler on the RS/6000:
  12.  
  13. In article <2286@devnull.mpd.tandem.com> you write:
  14. >
  15. >Could one of the ANSI-C++ folks that have "paper experience" :-)
  16. >with how exception handling is supposed to work give a summary of how
  17. >will an exception thrown from a constructor interact with objects
  18. >previously constructed in the same "try" block.
  19.  
  20. An exception in a constructor will destroy the object being constructed
  21. (as far as it has been constructed), then destroy all previously constructed
  22. objects in the try block, and then try matching the catch clauses.  This will
  23. repeat up the static and dynamic blocks until a catch block is found that
  24. matches the exception, or else terminate() will be called.
  25.  
  26. >
  27. >Also would you please illuminate us on how an exception thrown from
  28. >the constructor of a derived object (which executes after the construction
  29. >of the base object) interacts with the destruction of the base object.
  30. >Will the destructor for the base object be called when the exception
  31. >is thrown?
  32.  
  33. Any part of the object that has been created will be destroyed (in reverse
  34. order).  In particular the base destructor will be called, but not the 
  35. derived destructor, because the derived object isn't completely contructed
  36. yet.
  37.  
  38. >
  39. >What about an exception thrown from a signal handler (yuck!) that
  40. >interrupted the construction of an object?
  41.  
  42. Under xlC, you are not allowed to do a throw from a signal handler.  This
  43. restriction is due to the implementation of exception handling.  Different
  44. implementations might allow you to do this.  On the other hand, the only
  45. portable action allowed by ANSI C in a signal handler is to set a variable
  46. of type sigatomic_t.
  47. -- 
  48. Mark Mendell
  49. IBM Toronto Lab
  50. mendell@torolab6.vnet.ibm.com
  51.