bug-myserver
[Top][All Lists]
Advanced

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

Re: [bug-myserver] [PROPOSAL] Exception management scheme


From: Giuseppe Scrivano
Subject: Re: [bug-myserver] [PROPOSAL] Exception management scheme
Date: Mon, 29 Mar 2010 01:17:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.93 (gnu/linux)

The idea behind the macro was to avoid code duplication as the same
macro (or a function) could be used to decorate any call to posix
functions.

For example, writing it as a function:

int
checkPosixCall (int retcode)
{
  if (retcode < 0)
     ExceptionsHandler::throwPosixException (errno);

  return retcode;
}

I agree with you that this can lead to less-readable code as it will
look like:

int read = checkPosixCall (gnulib::read (file, buffer, buffersize));


While your idea, from what I have understood, is to have something like:

int read = safecall::read (file, buffer, buffersize);


It will require some more work, as we will need to have a replacement
for any function using errno, but the advantage is code readability.

We can think of some scripts to do it automatically for us.
The only thing I don't like of this solution is that we will need to
keep safe synchronized every time a new function using errno appears;
any idea?


Giuseppe



Daniele <address@hidden> writes:

> Hi! :)
> Well, my only comment is related to the CHECK_CONDITION() system, on which I 
> briefly answered earlier. I'll try to explain
> more clearly why I think that a function or a macro is not a choice I like 
> best.
>
> First, it seems to me like a really heavy "notation", which would make some 
> pieces of code difficult to read (and IMO the
> overall look of the code is an important factor in a project).
>
> Moreover, the errno symbol value (as stated on the man page: 
> http://linux.die.net/man/3/errno) "is significant only when
> the call returned an error": making a single macro or function would imply 
> writing a routine which first checks the return
> code of a system call, and then checks the value of errno. But, since the 
> system calls can return an arbitrary value  -
> even negative values, such as in the case of the getpriority() call 
> (http://www.kernel.org/doc/man-pages/online/pages/man2/
> getpriority.2.html) - a single "god-like" function which handles all the 
> possible cases would have to first reset the errno
> symbol value to EOK (or 0), then evaluate the requested expression, and 
> finally check back the errno symbol value to detect
> for a possible error condition, and subsequently raise the correct exception. 
> It would be possible with a macro, but it's
> tricky nonetheless. =)
>
> I find a more natural approach to define "aliases" of the syscalls in a 
> separate namespace, so that the readibility is not
> heavily impacted and the goal of handling system calls failures with 
> exceptions is accompished in a custom way for every
> function.
> To reduce code duplication, one may set up a map of factory methods that 
> create exceptions according to the errno-code they
> are associated with.
>
> I'm sorry for the length of the message, and I beg your pardon if something 
> is not explained clearly: I'll be glad to
> answer and clear your doubts, if this is the case.
>
> Cheers,
> Daniele
>
> 2010/3/28 Giuseppe Scrivano <address@hidden>
>
>     Hello Lisa,
>    
>     As we already discussed privately, it looks like a good proposal and I
>     agree on everything.
>    
>     Does anyone have comments?
>    
>     Cheers,
>     Giuseppe




reply via email to

[Prev in Thread] Current Thread [Next in Thread]