|
-
Aug 23rd, 2003, 10:34 AM
#1
Thread Starter
Hyperactive Member
error handling
in vb handling errors is very simple... such as "on error resume next" or "on error goto blah .... blah: exit sub"
im real new to C# and was wondering on resources for error handling
also is there something like "on error resume next" or something like that in C#?
-
Aug 23rd, 2003, 11:47 AM
#2
Sleep mode
What do you think of try ..catch block or goto keyword .Check them out in the Help Files .
-
Aug 23rd, 2003, 03:33 PM
#3
Frenzied Member
try...catch would be your best bet when attempting to handle errors in C#.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Aug 23rd, 2003, 05:53 PM
#4
a quick example....
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] }
}
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Aug 23rd, 2003, 11:04 PM
#5
Thread Starter
Hyperactive Member
ahh... many thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|