As in the topic, I'm curious if an event listener can receive a null event and if that needs to be checked against for safety.
Code: Select all
void AddListeners()
{
_sfClientInterface.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
}
private void OnConnectionLost(BaseEvent evt)
{
string reason = (string)evt.Params["reason"];
Log(reason);
<other logic here>
}
I am receiving some reports from other developers on the project that they seeing null exceptions in OnConnectionLost, and they believe that it is the BaseEvent "evt" that is null. I believe it may be the other code we have in the <other logic here> section, but I could not find anything on the documentation that specified whether or not the event coming into a function called from an EventListener was guaranteed to not be null. Is this the case? Or is the best practice to have an
if (evt != null) safety check?