Structured exception information



Hi,

Consider an object created by a constructor function:

X : My_Type := My_Constructor(Some_Parameters);

My_Type is Controlled_Limited to ensure control over initialization and finalization. The idea of constructor function is to prevent the existence of objects that are not yet initialized, half-baked, in a bad state, etc. If the object exists, it's ready for use.

If there are problems during the execution of the constructor function, the exception is raised, so that there is no X object in a bad state.
How can I pass some error information from the constructor function out, so that it's used when the exception is handled?
Obviously, some message can be attached to the exception occurence, but it doesn't scale well - I might want to pass some more data, possibly structured (some error code, some reason code, some timestamp, some whatever else, ...).

Yes, I'm asking for "throwing objects", in the C++ parlance.

How to do this in Ada?
If I cannot - how to solve this design problem?

BTW - How can I ensure in a general way that the constructor function must be used to initialize the object, otherwise compile-time error is reported?
If I make My_Type a discriminated type (so that the discriminant value is used in the default initialization), does it limit anything, like constructor parameter types?

--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/
.



Relevant Pages

  • Re: Structured exception information
    ... initialization expression. ... Consider an object created by a constructor function: ... the exception is raised, so that there is no X object in a bad state. ... If I make My_Type a discriminated type (so that the discriminant value ...
    (comp.lang.ada)
  • Re: How to set my own program startup in f77 programs other than MAIN__
    ... FX suggestion to use a constructor function for the library is a ... without relying on compiler initialization specifics. ... Yes, gfortran and g77 differ, but the principle is the same. ...
    (comp.lang.fortran)
  • Re: Structured exception information
    ... Consider an object created by a constructor function: ... My_Type is Controlled_Limited to ensure control over initialization and ... the exception is raised, so that there is no X object in a bad state. ... The implementation of this routine would call ...
    (comp.lang.ada)
  • Re: Constant record components
    ... this does not meet the OP's interest in components that cannot be changed after initialization. ... To enforce the contract of the constructor function `make` ("call once ... type R is tagged private; ...
    (comp.lang.ada)
  • Re: Structured exception information
    ... the exception is raised, so that there is no X object in a bad state. ... How can I pass some error information from the constructor function out, ... package Handling is ...
    (comp.lang.ada)