Try/ Catch does not work with Network.InitializeServer

Hey,
I’m trying to catch an exception on Network.InitializeServer in a C# script, but rather than throwing the exception it is treating it like normal (just throwing the exception in the log and continuing)

try {
	Network.InitializeServer(32, LevelInitiator.getInfo().HostingPort, false);
} catch(UnityException e) {
	Debug.Log(e.Message);
}

This is beign called in OnLevelWasLoaded, if that might cause a problem?
Should this be submitted as a bug report or am I missing something?
Thanks!

Ok, using the various comment. It seems you are not looking for an exception.

Network.InitializeServer returns an object of type NetworkConnectionError

I guess you could work work that.

NetworkConnectionError errorNet = Network.InitializeServer(32, LevelInitiator.getInfo().HostingPort, false);

There is a variable noError that you could use. Fact is I am not familiar with Network connection and the docs is actually quite poor on this as it does not show any example nor what is the type of noError.

Here are the NetworkConnectionError members

Not sure I’m understanding the question. The code you’re showing would handle the exception by logging it, then it would continue on because you’ve handled it in catch. If you want to log the exception and then quit you need to re-raise the exception by calling throw e; after you’ve logged it.

try
{    
  Network.InitializeServer(32, LevelInitiator.getInfo().HostingPort, false);
} 
catch(UnityException e)
{
  Debug.Log(e.Message);
  throw e;
}

C# documentation for try…catch: try-catch (C# Reference) | Microsoft Learn