Continue execution after an exception is thrown in C#

I am kind of new to C# but pretty familiar with the concepts of exception handling.

I am using the UdpClient class and occasionally, the local port remains bound because the connection wasn’t closed properly.

When this occurs, the statement

UdpClient udpC= new UdpClient(Port);

throws an exception that I can catch but have found no way to force the system to continue execution beyond the catch/try block.

I realize catch/try is meant to be a terminal situation, but I cannot (easily) find a way to check for a bound port before calling the constructor.

Any help would be appreciated.

Execution should still continue after the catch (unless you bubble up the exception within the catch, or if you do not catch the correct exception type).

Do you mean the UdpClient no longer continues execution?

EDIT: well if the UdpClient throws an exception on instantiation, it won’t be created and won’t execute anything. In this case, wouldn’t you have to try again later when the port will hopefully be open?

try/catch should continue. It doesn’t automatically assert.

I think I found the problem; the code within the ‘catch’ block was throwing an exception.

Thanks!