try { // some code IPEndPoint ipEP = new IPEndPoint(paraIPAddress, iPort); Socket udpSocket = new Socket(ipEP.Address.AddressFamily,SocketType.Dgram,ProtocolType.Udp); // some more code } catch(Exception ex) { //Do something if exception is thrown } finally { //I need some code here to test if the socket is created/initialized udpSocket.Close(); }The contents of the code is not really important, but what can I use in the finally block to ensure that the object that I am trying to call the "clean-up" code for (in this case Close()) has been initialized? What if an error was thrown before the line Socket udpSocket = new Socket(...), I want to call Close() on the udpSocket in the finally block but only if the object udpSocket is defined.