Re: Tasty exceptions
- From: "Roddy Pratt" <roddy at spam fritter dot com>
- Date: Sat, 1 Jul 2006 23:09:41 +0100
"Michael C." <Michael@xxxxxxxxxx> wrote in message
news:44a6e7dc$1@xxxxxxxxxxxxxxxxxxxxxxxxx
I'm not convinced that code become unreadable, unmaintainable, and
unreliable if
one uses error checking using error codes.
Perhaps, an example would clarify this issue?
OK. Simple case: Assume you have a bunch of items to write to a container of
some kind. (file/socket/array/whatever. Every item you write may or may not
succeed. If a problem occurs, you want to inform the user
[You'll have to pardon my rusty delphi - I normally use C++, which is even
easier due to stuff like auto_ptr which removes the need for the 'finally']
var container: TContainerOfSomeKind;
begin
try
container := TContainerOfSomeKind.create("AlphaCentauri"); // specify
which star to keep our container on
container.AddWeapon("Phaser","SetToStun");
container.AddPerson("Scotty");
container.AddPerson("Captain");
container.AddItem("Tribble1");
container.AddItem("Tribble2");
...
container.AddItem("TribbleN");
catch Exception &e
ShowMessage("I'm sorry: Your container couldn't be filled due to
"+e.message);
finally
container.delete;
end;
end;
-----------------------
Now, you write it with error-checking on each function return.
- Roddy
.
- Follow-Ups:
- Re: Tasty exceptions
- From: Michael C.
- Re: Tasty exceptions
- References:
- Re: Tasty exceptions
- From: Michael C.
- Re: Tasty exceptions
- Prev by Date: Re: Tasty exceptions
- Next by Date: Re: Tasty exceptions
- Previous by thread: Re: Tasty exceptions
- Next by thread: Re: Tasty exceptions
- Index(es):
Relevant Pages
|