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:

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

    ReplyDelete
  2. Jan Derk21:08

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

    ReplyDelete
  3. 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

    ReplyDelete
  4. If you like it that way, why not.

    ReplyDelete