473,385 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

On Error translation

Hello,
I'd like to know what the C# counterpart is for the VB On Error statement ?
My VB code looks like this :

On Error GoTo ErrGetItem

plain simple ud say, but I need to "translate" it into C#...
Any ideas ???
Nov 16 '05 #1
5 6557
Hi tiger79,

I'm not entirely certain how On Error works, but I think you may mean try-catch(-finally)

// code

try
{
// code that may case exceptions
}
catch(SpecificException ex)
{
// error handling code for specificexception
}
catch(GeneralException ex)
{
// error handling code for all generalexceptions not caught by specific...
}
catch(Exception ex)
{
// catch everything still not caught
}
finally
{
// code that needs to run no matter what
}

// code that runs if no exception was thrown

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

hhhmmm... that may work... i'll try it out as soon as I can, cause I got
other problems as well, look at my newer post ;)
thanx anyways...

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opr9xti9pgklbvpo@morten_x.edunord...
Hi tiger79,

I'm not entirely certain how On Error works, but I think you may mean try-catch(-finally)
// code

try
{
// code that may case exceptions
}
catch(SpecificException ex)
{
// error handling code for specificexception
}
catch(GeneralException ex)
{
// error handling code for all generalexceptions not caught by specific...
}
catch(Exception ex)
{
// catch everything still not caught
}
finally
{
// code that needs to run no matter what
}

// code that runs if no exception was thrown

--
Happy coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #3
No direct translation is possible for that single line - the VB to C#
converter Instant C# (www.instantcsharp.com) has the
following example:

VB code with On Error ... statements:
Public Sub UnstructuredErrorHandlingExampleOne()

On Error GoTo ErrorHandler

'... <main logic>

On Error Resume Next 'this won't be converted

'... <more main logic>

'turn off error handling:
On Error GoTo 0

'... <more main logic>

Exit Sub

ErrorHandler:
'... <error handling code>
Resume 'this won't be converted

End Sub

C# code produced by Instant C#:
public void UnstructuredErrorHandlingExampleOne()
{
string ActiveErrorHandler = "";
try
{

// On Error GoTo ErrorHandler
ActiveErrorHandler = "ErrorHandler";

//... <main logic>

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

//... <more main logic>

//turn off error handling:
// On Error GoTo 0
ActiveErrorHandler = "";

//... <more main logic>

return;

}

catch
{
if (ActiveErrorHandler == "ErrorHandler")
{
//... <error handling code>
//INSTANT C# TODO TASK: The simple 'Resume' statement is not converted
by Instant C#:
Resume //this won't be converted

}
}
}
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #4
GoTo? EEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeee!!!!!!!!

"tiger79" <po**@freemail.nl> wrote in message
news:e0**************@TK2MSFTNGP11.phx.gbl...
Hello,
I'd like to know what the C# counterpart is for the VB On Error statement ? My VB code looks like this :

On Error GoTo ErrGetItem

plain simple ud say, but I need to "translate" it into C#...
Any ideas ???

Nov 16 '05 #5
Hi, JetsonG

Replace on error with try
Put catch / end try before end sub or before next on error if you have it

HTH
Alex

"JetsonG" <je****@spacely.com> wrote in message
news:aM********************@dls.net...
GoTo? EEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeee!!!!!!!!

"tiger79" <po**@freemail.nl> wrote in message
news:e0**************@TK2MSFTNGP11.phx.gbl...
Hello,
I'd like to know what the C# counterpart is for the VB On Error
statement ?
My VB code looks like this :

On Error GoTo ErrGetItem

plain simple ud say, but I need to "translate" it into C#...
Any ideas ???


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Amy Kimber | last post by:
Hello, I have a file upload page, and I've had it working fine, it was beautiful :-) Anyway, the powers that be moved hosts... and it doesn't work now. The file name is correct, the directory...
1
by: Jean-Marc Blaise | last post by:
Hi, I've noticed that on my ESE v8.1 DB2 install on W2K (french), there is a translation error on the service: "Serveur DB2 remote command". In fact, all services start with "DB2", and have a...
10
by: Sune | last post by:
Hi, previously I used Eclipse CDT for compiling my files just to get started with C and leave C++ behind. Now it's time to get a little more serious so I've moved my files to a new workplace and...
3
by: TGF | last post by:
Hello, When I attempt to set the icon property on a Windows form (.NET), when I go to compile, I get the following error.... e:\Projects\MyApp\AboutForm.h(108): error C2039: 'GetObjectA' : is...
33
by: Martin Jørgensen | last post by:
Hi, In continuation of the thread I made "perhaps a stack problem? Long calculations - strange error?", I think I now got a "stable" error, meaning that the error always seem to come here now...
2
by: Robbie Hatley | last post by:
"Victor Bazarov" <v.Abazarov@comAcast.net> wrote: > Robbie Hatley wrote: > > > > I ran into a problem a few days ago when I added a couple of > > template functions to one of my personal...
0
by: zoobave | last post by:
Hi, When i give "apt-get update" command, i got the following errors. How can i resolve it? root@dvm-desktop:/home/dvm# apt-get update Get:1 http://security.ubuntu.com feisty-security...
14
by: yeah | last post by:
hi all I am working with linux environment and i compiled device driver programs using native compiler "gcc".In one of my macro i have these lines #if (1 << HARDIRQ_BITS) < MAX_HARDIRQS_PER_CPU...
11
by: Tim H | last post by:
The following program compiles just fine in C, but not in C++. Can anyone explain why? I have a chunk of code that defines stuff like this in headers (without the extern) that I can not easily...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.