comp.lang.ada
 help / color / mirror / Atom feed
* Exceptions vs Error return values
@ 2001-08-05 21:28 Hambut
  2001-08-05 22:30 ` tmoran
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Hambut @ 2001-08-05 21:28 UTC (permalink / raw)


I'm currently trying to get to grips with winsock programming.  As
part of this process I'm trying to put together a slightly higher
level binding to the thin one provided with Gnat.

The 'thin' binding provides a lot of functions returning an
integer. The value of this integer encodes a whole range of possible
errors.  I want to replace this 'C'-esque way of doing stuff with Ada
exceptions; my question is "What is a sensible guideline for choosing
between exceptions and error return codes?"

Looking at some of the error codes there are a couple that seem
natural exceptions. For example when
1  Winsock hasn't been initialised by a call to WSAStartup, or when
2  Winsock detects that the network has fallen over.

In both cases Winsock is not able to fulfil the service to the client
(in the case of 1 because of improper use by the client, and in the
case of 2 due to some external event), so the client needs to be
notified in no uncertain terms that something is wrong.

But there are other cases that are less obvious, for example when
1  The Winsock call returns no data, or when
2  The operation has been blocked by another windows socket operation.

In both cases Winsock is still able to fulfil the services it's
offering.  The client may continue to use its services, but it is
advisable for the client to take some kind of action.

Would it be a sensible guideline to relate the use of exceptions to
the severity of error (for example as described in table below)?

Exception/  : Error Type
Error Value : 
------------:------------------------
Exception   : Server package about to overwrite all memory with garbage
Exception   : Server package can not fulfil offered services
Error Value : Server package can not fulfil called service with
            :  provided parameters
Error Value : Service results in a 'not-expected' but correct result
            :  (e.g. returning a null host name) 

I've had a delve through Barnes, and through the Ada95 style guide,
and neither really helped to clear my mind on this point.


Any thoughts gratefully received...

Cheers,

Hambut.

p.s.  I suppose you could almost do both; a child package providing
'exceptions' and another child providing 'error values'.  That way the
client could choose the most appropriate mechanism for the
application.  Would this be useful, or just overkill?



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2001-08-06 21:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-05 21:28 Exceptions vs Error return values Hambut
2001-08-05 22:30 ` tmoran
2001-08-06 12:47 ` Stephen Leake
2001-08-06 13:57   ` Ted Dennison
2001-08-06 21:31 ` Freddy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox