473,574 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4709
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******** ********@TK2MSF TNGP14.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2510
by: John Ramsden | last post by:
I have a PHP script that is run via a 'wget' command within an MS SQL trigger, and relies on accessing the database record updated by the SQL statement that triggered the script in the first place. For this reason, to avoid the script reading the old record or getting into a deadly embrace, it must "return" in order to complete the 'wget'...
2
4705
by: Mark | last post by:
Hello all, I know why the following doesn't work ... I can't figure out how to make it work like I want it to. Basically, I only want the loop computing fibonacci numbers to run for approx 5 seconds. The timer fires, the exception is raised, but it is not caught ... because the execution stack for the function that raises isn't in the...
8
2712
by: StepH | last post by:
Hi, I've this module : from optparse import OptionParser import re _version = "P1" def writeVar(f, line):
1
2041
by: Tolga Erdogus | last post by:
Hi, I have the following code: for (int i=0;i<childOptimizations.Length;i++) //for each partition { row = childOptimizations;
4
2025
by: Robbie Hatley | last post by:
I've been playing with "auto_ptr" and the "Resource Acquisition Is Initialization" concept. On page 199 of Lippman's book "Effective C++" he says "All active local class objects of a function are guaranteed to have their destructors applied before termination of the function by the exception handling mechanism.". I don't think that's...
2
4662
by: Bassel Tabbara | last post by:
I wrote the following code: oApp = new Outlook.Application(); oApp = new Outlook.Application(); oNameSpace= oApp.GetNamespace("MAPI"); oNameSpace.Logon(null,null,true,true); //gets defaultfolder for my Outlook Outbox oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox); But it won't work and it is giving...
12
6729
by: Subhransu Sekhar Sahoo | last post by:
Hi All, I have a doubt in the implementation of C++ try catch exception handling procedure. Whenever there is a through, the execution has to go to the point of catch. Now, if the catch block resides across DLL boundary (i.e. The Catch block is there in another DLL). In that case the compiler can not put the code for jumping to the catch...
17
5056
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also identifying memory leaks. The application in question is the Mozilla Web Browser. I also have had similar tasks before in the compiler construction area....
2
1057
by: rajnipankar | last post by:
I want to Exit from the void Procedure, is there any stmt like VB Exit Function, or return; stmt in the value returning function . I want the same in the Void function, like below private void myFunctionName(int status) { if(status==0) //here i want to exit from the function //below various code goes here... }
0
7832
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7747
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8262
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8129
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6498
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3768
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3785
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2262
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.