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?
It *was* clear first time around, even for would-be smart arses (or at least, should have been)...
ReplyDeleteIt was clear to me too, but maybe because I do exactly what you do.
ReplyDeleteHow about write a function instead of putting your raise directly there?
ReplyDeleteprocedure 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
If you like it that way, why not.
ReplyDelete