Results 1 to 5 of 5

Thread: Error Handler

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Cairo, Egypt
    Posts
    126

    Error Handler

    Hi All;
    How could I make an error handler in C# in the procedure or sub or function. And is there any command or ... like VB keyword WithEvents to have the events of the object type like the connection to the database to handle it's events????

  2. #2
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    Re: Error Handler

    This is how to handle errors in C#

    http://msdn.microsoft.com/library/de...ogether_PG.asp
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: Error Handler

    Exceptions are handled the same way in all .NET languages, with Try-Catch blocks. In C# the syntax would be...
    Code:
    private void doSomething() {
    
      try {
        doSomethingElseThatWillPossiblyThrowAnException();
      } catch (Exception ex) {
        MessageBox.Show( ex.Message );
      }
    
    }
    in a simplistic form.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    Re: Error Handler

    Quote Originally Posted by Bobbo70
    Hi All;
    ...like VB keyword WithEvents to have the events of the object type like the connection to the database to handle it's events????
    I dont think that the WithEvents statement exists in C# and I dont think there is an equivilant! Sorry! Maybe some else knows?

    Stephan
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Error Handler

    There is no C# equivalent to WithEvents because any variable that is of a type that has events can simply have an event handler attached to the event using "+=". It's as though WithEvents is implicitly included in every variable declaration.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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