Re: GNOME GTK-- Projects



On Mon, 1 Jun 1998, Michael Hudson wrote:

> On Mon, 1 Jun 1998, John R Sheets wrote:
> > I'm definitely a fan of exception handling.  Granted, I'm
> > somewhat new to the UNIX end of things, but would there be any
> > way to write a class to attach to stderr and parse its output,
> > looking for errors?  Or is GTK+ consistent enough in its
> > reporting formats to make this feasible?  Perhaps a virtual
> > exception scheme would be possible, where a GTK+ error string
> > would trigger an exception throw that GTK-- could pick up?  I
> > don't know.  I'm just tossing ideas out like playing cards right
> > now...
> > 
> 
> There's no guarantee that would work, because the exceptions would have to
> propogate through gtk code, which is in C, not C++. It might work with
> gcc/g++, but it might not work everywhere. (it wouldn't work using
> CodeWarrior on the Mac, not that that's an issue here, just an example
> that it _doesn't_ always work).
> 
> Michael Hudson

Well here is what I think should happen, IMHO of course.  Modify Gtk+ so 
that it has something like the following APIs:

	typedef struct GtkErrorStruct {
		int error_num;
		int line_number;
		gchar file[GTK_MAX_ERROR_FILE];
		gchar msg[GTK_MAX_ERROR_MSG];
		gchar time[GTK_MAX_ERROR_TIME];
	}

	// Currently defined error policies
	#define GTK_EXIT_ON_ERROR		1
	#define GTK_RETURN_ERRORS		2
	#define GTK_USER_ERROR_HANDLER		3
	#define GTK_USER_ASYNC_ERROR_HANDLER	4

	int gtk_set_error_policy( int error_policy);
	int gtk_get_error_policy( void);
	
	// Currently defined error log policies
	#define GTK_LOG_TO_TTY		1
	#define GTK_LOG_TO_FILE		2
	#define GTK_BE_QUIET		3

	int gtk_set_error_log_policy( gchar* szFileName, int error_log_policy);
	int gtk_get_error_log_policy( void);
	

	typedef void (*GTK_ERROR_HANDLER_FUNC_PTR)( GtkErrorStruct error);

	int gtk_assign_error_handler( GTK_ERROR_HANDLER_FUNC_PTR );
	GTK_ERROR_HANDLER_FUNC_PTR gtk_get_error_handler( void);

	void gtk_set_error_struct( GtkErrorStruct*);
	GtkErrorStruct gtk_get_error_struct( void);

	// Here are some error info masks
	enum {
		GTK_ERROR_NUMBER=1,
		GTK_ERROR_LINE=2,
		GTK_ERROR_FILE=4,
		GTK_ERROR_MSG=8,
		GTK_ERROR_TIME=16
	};
	#define GTK_ERROR_DEFAULT ( GTK_ERROR_NUMBER | GTK_ERROR_MSG)
	#define GTK_ERROR_DEBUG ( GTK_ERROR_NUMBER | GTK_ERROR_LINE | 
			GTK_ERROR_FILE | GTK_ERROR_MSG | GTK_ERROR_TIME )
	
	int gtk_set_error_info_mask( mask );
	int gtk_get_error_info_mask( void );
	


Anyway, with something like this in place, anybody writing an application
(or a wrapper library) could then simply write their own error handler 
function.   For example, Gtk-- could write an error handler that looks like:

void GTKmm_GTK_Error_Handler(GtkErrorStruct error)
{
	throw (error);
}

which will get called by gtk+ when an error occurs.   It is then very easy 
to modify the Gtk--.m4 macro to ensure that the right thing is done by the 
compiler WRT exceptions to ensure that this is handled.
 
 -Erik

--
Erik B. Andersen   Web:    http://www.inconnect.com/~andersen/ 
                   email:  andersee@debian.org
--This message was written using 73% post-consumer electrons--




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]