Andre Kostur
11/25/2008 6:42:00 PM
Daniel Koch <daniel.koch@gmail.com> wrote in
news:c9504ae1-a7ca-42d9-8c1a-4186b2020d6f@t2g2000yqm.googlegroups.com:
> Hi, I've this Exception class:
>
> // exception.h file
> #ifndef EXCEPTION_H
> #define EXCEPTION_H
>
> #include <glibmm.h>
> #include <gtkmm/messagedialog.h>
>
> class Exception
> {
> private:
> Glib::ustring error_message;
>
> public:
> Exception(Glib::ustring s);
> void DisplayError();
>
> protected:
> Glib::ustring getErrorMessage(){ return error_message; }
> };
>
> #endif
>
> // exception.cpp file
> #include "exception.h"
>
> Exception::Exception(Glib::ustring s)
> {
> error_message = s;
> }
>
> void Exception::DisplayError()
> {
> // display dialog
> Gtk::MessageDialog dialog("System Error", false,
> Gtk::MESSAGE_ERROR);
>
> dialog.set_secondary_text(error_message);
> dialog.run();
> }
>
>
> I need to identify when it is a System Error or when it is an
> Application Error. Then it could be extended to a child class:
> ApplicationException.
>
> My question is about "System Error" MessageDialog's title. How it can
> be implemented? How it can be changed when I'll define the
> ApplicationError class?
If you have SystemErrorException and ApplicationErrorException children
classes of Exception, you could declare a pure virtual method "virtual
const char * DialogTitle() const = 0". In the children classes implement
that method to return the appropriate title. In Display Error use:
"Gtk::MessageDialog dialog(DialogTitle(), false);". Don't forget to also
make your destructor virtual as well.