471,318 Members | 3,223 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

Continuing execution following an Exception, and Exiting a Function...

RSH
Hi,

I have two questions both by a VB programmer that is learning C#...

1) In a VB error trap routine we would commonly trap the error and write it
to an error log and then attempt to "Resume Next." I have set up an
Exception Handling routine in C# and I would like to do the same thing. How
do I call an equivelent of "Resume Next" in C#

2) I have a situation in which I am performing a logical evalutaion
following a database call at the beginning of a function. If the evaluation
returns true then I have no reason to run the rest of the function...so how
do I call the equivelent of VBs "Exit Function...or Exit Sub Routine" ?
Thank you for your help!
Ron
Dec 29 '05 #1
3 4643
Just a couple of general answers to your questions. Others may have
better solutions.

1. I assume you have vb code similar to this:

On Error GoTo ErrorHandler
'Some code here that might cause an error
ErrorHandler:
'Log error here
Resume Next

Generally speaking you would use code similar to this in C# (watch out
for typos):

try
{
'Some code here that might cause an exception
}
catch (Exception ex)
{
'Log exception here
}
'Code execution resumes here

2. To exit a method in C# you simply call return

Dec 29 '05 #2
>1) In a VB error trap routine we would commonly trap the error and write it
to an error log and then attempt to "Resume Next." I have set up an
Exception Handling routine in C# and I would like to do the same thing. How
do I call an equivelent of "Resume Next" in C#
You write try/catch/finally blocks as needed. Execution continues
after the block after any exception handler and finally block has
executed.

2) I have a situation in which I am performing a logical evalutaion
following a database call at the beginning of a function. If the evaluation
returns true then I have no reason to run the rest of the function...so how
do I call the equivelent of VBs "Exit Function...or Exit Sub Routine" ?


return;

or

return yourReturnValue;
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 29 '05 #3
RSH
THANKS!
"RSH" <wa*************@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

I have two questions both by a VB programmer that is learning C#...

1) In a VB error trap routine we would commonly trap the error and write
it to an error log and then attempt to "Resume Next." I have set up an
Exception Handling routine in C# and I would like to do the same thing.
How do I call an equivelent of "Resume Next" in C#

2) I have a situation in which I am performing a logical evalutaion
following a database call at the beginning of a function. If the
evaluation returns true then I have no reason to run the rest of the
function...so how do I call the equivelent of VBs "Exit Function...or Exit
Sub Routine" ?
Thank you for your help!
Ron

Dec 29 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by John Ramsden | last post: by
2 posts views Thread by Mark | last post: by
8 posts views Thread by StepH | last post: by
1 post views Thread by Tolga Erdogus | last post: by
4 posts views Thread by Robbie Hatley | last post: by
12 posts views Thread by Subhransu Sekhar Sahoo | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.