- Joined
- May 29, 2009
- Sythe Gold
- 0
- Messages
- 46
I've noticed many people do not know how to use try/catch/finally correctly..
In short, the try statement will execute the lines within it, if it cannot succeed it moves to the catch, and finally will ALWAYS execute.
I've designed a simple ping / portscan application to demonstrate.
Sorry for the sloppiness, I wrote this in the post itself.
I hope people have learned the functionality of Try/Catch/Finally Statements.
In short, the try statement will execute the lines within it, if it cannot succeed it moves to the catch, and finally will ALWAYS execute.
I've designed a simple ping / portscan application to demonstrate.
Code:
System.Net.Sockets.TcpClient tcp = new System.Net.Sockets.TcpClient();
string ip = "127.0.01";
int startPort = 1
int endPort = 100
for (int x = startPort; x <= endPort; x++;)
{
try
{
tcp.Connect(ip, x);
Console.WriteLine("Port: " + x.toString() + " is open.'');
}
catch
{
Console.WriteLine("Port: " + x.ToString() + " is closed...");
}
finally
{
Console.ReadLine();
}
}
Sorry for the sloppiness, I wrote this in the post itself.
I hope people have learned the functionality of Try/Catch/Finally Statements.





