By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Reza wrote:
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)
{
...
}
}
--
Tom Porterfield
Nov 16 '05 #2

P: n/a
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
}
}
}
"Tom Porterfield" <tp******@mvps.org> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Reza wrote:
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)
{
...
}
}
--
Tom Porterfield

Nov 16 '05 #3

P: n/a
<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 }

"spmm#" <sp******@yahoo.com> wrote in message
news:41***********************@news.xs4all.nl...
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
}
}
}
"Tom Porterfield" <tp******@mvps.org> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Reza wrote:
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)
{
...
}
}
--
Tom Porterfield


Nov 16 '05 #4

P: n/a
Scot McDermid wrote:
<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.
--
Tom Porterfield
Nov 16 '05 #5

P: n/a
(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(Micros oft.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
*-----------------------*
Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.