how can I convert this snippet to c#-please help

  • Thread starter Thread starter Reza
  • Start date Start date
R

Reza

How can I change the following code to the equivalent in C#



Public Class EventSink : Implements IListEventSink

Public Sub OnEvent(ByVal listEvent As Microsoft.SharePoint.SPListEvent)
Implements Microsoft.SharePoint.IListEventSink.OnEvent

On Error Resume Next

.........

End Class 'EventSink

End class




thanks for your time
 
Reza said:
How can I change the following code to the equivalent in C#



Public Class EventSink : Implements IListEventSink

Public Sub OnEvent(ByVal listEvent As Microsoft.SharePoint.SPListEvent)
Implements Microsoft.SharePoint.IListEventSink.OnEvent

On Error Resume Next

.........

End Class 'EventSink

End class

C# has no On Error Resume Next. Rather it has structured error handling
through the use of try/catch/finally. But basically the C# code would
look like:

class EventSink : Microsoft.Sharepoint.IListEventSink
{
public void OnEvent(Microsoft.SharePoint.SPListEvent listEvent)
{
...
}
}
 
Doesn't On Error Resume Next mean: "when I encounter an error, just
continue, pretending the error never happened"??

Wouldn't this be done in C# by catching the error without throwing it?? Like
this:

class EventSink : Microsoft.Sharepoint.IListEventSink
{
public void OnEvent(Microsoft.SharePoint.SPListEvent listEvent)
{
try
{
...
}
catch
{
//do nothing with the caught error
}
}
}
 
<top posting continued>
Seems to me that to recreate an "On Error Resume Next" in C#
you would surround each and every line [that could produce an exception]
with a try/catch block
that is:
try { one statement; } catch (Exception e) { // do nothing)
try { next statement; } catch (Exception e) { // do nothing }
 
Scot said:
<top posting continued>
Seems to me that to recreate an "On Error Resume Next" in C#
you would surround each and every line [that could produce an exception]
with a try/catch block
that is:
try { one statement; } catch (Exception e) { // do nothing)
try { next statement; } catch (Exception e) { // do nothing }

Exactly. On Error Resume Next means to continue processing no matter
which line of code generates the error. To reproduce that exact
behavior in C# you would have to try every line of code and do nothing
with the caught exception. You could shorten your coding slightly by
using a parameterless catch. Ex:

int x = 0;
try {int y = 1/x;}catch{}
try {Console.WriteLine("{0}", 1/x);}catch{}
try {Console.WriteLine("this is painful");}catch{}

When you see it that way it augments how it is almost always bad idea to
use On Error Resume Next in VB.
 
(Didn't you post this somewhere else?)
Our VB.NET to C# converter, Instant C#, gives:

public class EventSink : IListEventSink
{

void
Microsoft.SharePoint.IListEventSink.OnEvent(Microsoft.SharePoint.SPListEvent
listEvent)
{
OnEvent(listEvent);
}
public void OnEvent(Microsoft.SharePoint.SPListEvent listEvent)
{

//TODO: INSTANT C# TODO TASK: The 'On Error Resume Next' statement is
not converted by Instant C#:
On Error Resume Next

.........;

}

Note that it is highly impractical to convert "On Error Resume Next".
As the others have indicated, you would need try/catch around every
line within the scope of the On Error Resume Next.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
Back
Top