I think this is a "best practice" category question:
I have a custom control - some kind of grid that holds some panels. One of the panels is the current active panel (the last one clicked).
TMyGrid = class (TSomeKindOfGrid)
published
property CurrentPanel: TPanel read getCurPanel write setCurPanel;
end;
My question is: if at a certain point someone asks for the CurrentPanel
and the grid is empty, should getCurPanel
return a NIL or should it raise an exception?
- If
getCurPanel
returns NIL, then I MUST check for NIL everywhere/every-time I callCurrentPanel
. There is also a possibility that the caller forgets to check for NIL. Well, nothing "bad" will happen since it will try to access a NIL object. The program will nicely crash right there. And I get to get a stack trace. - If I raise an exception in
getCurPanel
, I only do the check in one place (yes, I'm lazy).