From: Christian C. <chc...@cl...> - 2001-05-30 05:36:01
|
Eric Bezault wrote: > > Christian Couder wrote: > > > > I would rather have a base class using error variables and a derived > > class (inheriting the base class) with exceptions. > > Or something like this. I think it's far better than two set of routines > > (doing essentialy the same thing) in the same class. > > Why not. What do you think about that Berend? > > On the other hand with the first solution that I suggested > (deciding at creation time of the object if it will raise > exceptions or if it only uses an error variable) we can have > only one set of routines which call a `set_last_error' > routine when an error occur: > > set_last_error (...) is > -- ... > do > last_error := .... > if exeptions_enabled then > raise (...) > end > end Yes, but every object will have an exeptions_enabled attribute, this means the size of each object will increase. Perhaps there should be a global error manager object (a once object) using an error handler, like this: class ERROR_MANAGER feature current_error_handler: ERROR_HANDLER; default_error_handler: ERROR_HANDLER; creation make feature make(error_handler: ERROR_HANDLER) is do default_error_handler := error_handler current_error_handler := default_error_handler end set_new_error_handler(error_handler: ERROR_HANDLER) is do current_error_handler := error_handler end reset_error_handler is do current_error_handler := default_error_handler end set_last_error(error: INTEGER; error_creator: ERROR_CREATOR) is do ... current_error_handler.handle_error(error, error_creator) end end The error handler objects could all inherit from the same base class and do what should be done in case of an error (nothing or raise an exeption or send a mail or trace the error, ...) Also the error manager could have a dictionary to save the last error for each object that had an error. It would save space in each object since hopefully very few objects will have errors. Regards, Christian. |