Friday, May 11, 2007

Case .. else raise, again

Yesterday I used a really bad example which got most of my readers thinking about how most of the code could be optimized away. As that was not the idea behing my post, I decided to give a better example. This one is straight from the production code:

case mafWorkerOwner.PostToThread(MSG_AF_SCHEDULE_VIDEO, clonedBuffer) of
mqpOK:
Result := ClearError;
mqpTimeout:
Result := SetError(ERR_MXFFILTER_THREAD_TIMEOUT,
'Timeout while sending message to the worker thread');
mqpQueueFull:
Result := SetError(ERR_MXFFILTER_QUEUE_FULL,
'Cannot send message to the worker thread - queue full');
else raise Exception.Create('TMXFAsyncFilter.ScheduleVideo: Unexpected PostToThread result');
end; //case PostToThread

Am I making more sense now?


Technorati tags: , ,

4 Comments:

Blogger Chris said...

It *was* clear first time around, even for would-be smart arses (or at least, should have been)...

15:58  
Anonymous Jan Derk said...

It was clear to me too, but maybe because I do exactly what you do.

21:08  
Blogger stanleyxu said...

How about write a function instead of putting your raise directly there?

procedure UNHANDLED_CASE(const Msg: string);
begin
{$IFOPT C+} //debugger mode
raise ....
{$ENDIF}
end;

function UNHANDLED_CASE(const Msg: string; ExpectedValue: Boolean): Boolean;
begin
...
end;

function UNHANDLED_CASE(const Msg: string; ExpectedValue: Integer): Boolean;
begin
...
end;

And so on

11:03  
Blogger gabr said...

If you like it that way, why not.

11:31  

Post a Comment

Links to this post:

Create a Link

<< Home