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????
Printable View
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????
This is how to handle errors in C#
http://msdn.microsoft.com/library/de...ogether_PG.asp
Exceptions are handled the same way in all .NET languages, with Try-Catch blocks. In C# the syntax would be...
in a simplistic form.Code:private void doSomething() {
try {
doSomethingElseThatWillPossiblyThrowAnException();
} catch (Exception ex) {
MessageBox.Show( ex.Message );
}
}
I dont think that the WithEvents statement exists in C# and I dont think there is an equivilant! Sorry! Maybe some else knows?Quote:
Originally Posted by Bobbo70
Stephan
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.