Results 1 to 5 of 5

Thread: error handling

  1. #1

    Thread Starter
    Hyperactive Member Colonel Klink's Avatar
    Join Date
    Aug 2002
    Location
    Gold Coast, Australia
    Posts
    329

    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#?

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    What do you think of try ..catch block or goto keyword .Check them out in the Help Files .

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    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

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    a quick example....
    VB Code:
    1. [COLOR=BLUE]private[/COLOR] [COLOR=BLUE]void[/COLOR] button1_Click([COLOR=BLUE]object[/COLOR] sender, System.EventArgs e)
    2. {
    3.         System.IO.StreamReader sReader;
    4. [COLOR=BLUE]        try[/COLOR] [COLOR=GREEN]// try to open a file that doesn't exsist,to demonstrate the error handling.
    5. [/COLOR]        {
    6.         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));
    7. [COLOR=BLUE]        while[/COLOR](sReader.Peek()!=-1)
    8.         {
    9.             Console.Write(sReader.ReadLine());
    10.         }
    11.         }
    12. [COLOR=BLUE]        catch[/COLOR](Exception ex)
    13.         {
    14.             MessageBox.Show(ex.Message.ToString(),[COLOR=BLUE]this[/COLOR].Name,MessageBoxButtons.OK,MessageBoxIcon.Information); [COLOR=GREEN]// catch the error
    15. [/COLOR]        }
    16. }
    ~
    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]

  5. #5

    Thread Starter
    Hyperactive Member Colonel Klink's Avatar
    Join Date
    Aug 2002
    Location
    Gold Coast, Australia
    Posts
    329
    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
  •  



Click Here to Expand Forum to Full Width