VB Code:
[COLOR=BLUE]private[/COLOR] [COLOR=BLUE]void[/COLOR] button1_Click([COLOR=BLUE]object[/COLOR] sender, System.EventArgs e)
{
System.IO.StreamReader sReader;
[COLOR=BLUE] try[/COLOR] [COLOR=GREEN]// try to open a file that doesn't exsist,to demonstrate the error handling.
[/COLOR] {
sReader=[COLOR=BLUE]new[/COLOR] System.IO.StreamReader([COLOR=BLUE]new[/COLOR] System.IO.FileStream("D:\\some fake path.txt",System.IO.FileMode.Open,System.IO.FileAccess.ReadWrite));
[COLOR=BLUE] while[/COLOR](sReader.Peek()!=-1)
{
Console.Write(sReader.ReadLine());
}
}
[COLOR=BLUE] catch[/COLOR](Exception ex)
{
MessageBox.Show(ex.Message.ToString(),[COLOR=BLUE]this[/COLOR].Name,MessageBoxButtons.OK,MessageBoxIcon.Information); [COLOR=GREEN]// catch the error
[/COLOR] }
}