Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie 2 C# (VB programmer)... Try-Catch-Finally? 3

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
0
0
US
Sorry for the 'dumb question', but I have been coding in VB for the last 5 years or so and Basic in general (GWBASIC, QBASIC, etc...) for over 10 years...

I have done some C/C++ coding, though I never really got into it, since most of the stuff I need I can do in VB...

But in C# (and I believe in VB.Net?) I see this Try-Catch-Finally block everywhere, that I have never seen before...

Can someone give me a quick run through of what you would use it for and how it works...?

Is it simmilar to a switch (or select case) statement?

Or is it for error handling, or what?

Thanks,
Josh

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Quote (is there a way to do quotes on this group?):
So are VC# and VB.Net basically the same except for the
way you write your blocks, and syntax structure?

Actually, the syntax differences are more substantial than first appears. There's a good short summary of some of the more devious ones at
If you're a VB.NET programmer, you'll find switching to C# fairly easy, but I find that a converter like Instant C# is very useful (others are at
 
One other thing...

Is EVERYTHING object oriented in .NET?

I noticed if you Dim a variable such as
Dim S As String

then type
S.

You get a list of methods... for a string ?!?

So is this still a String Type or a String Object?

Quotes said:
To put things in quotes
Like This
You type...
Code:
[b][[/b][b]quote][/b]Like This[b][[/b][b]/quote][/b]

Or to say a name...
Josh said:
See ^ My Name

You Say...
Code:
[b][[/b][b]quote Josh][/b]See ^ My Name[b][[/b][b]/quote][/b]



Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Josh,
Josh said:
So is the IDE in VS.NET really that much better than #develop?
It's a lot, lot better. I hope your boss gives you the "Yes" so that you could try it out (don't do it illegally, though :))


About .NET's object orientedness
Everything in .NET is an object, yes, including strings. Integers and Doubles are also objects. As RiverGuy mentioned, inheritance plays an important role - as everything in .NET inherits from the object class, thus everything is an object.

But, objects are classified in two categories: value types and reference types. Although they are both objects, they behave slightly differently and value types have some features that set them apart from what we normally call "objects". Read about them at the MSDN Library

JC


Friends are angels who lift us to our feet when our wings have trouble remembering how to fly...
 
JC, I played with the {x} a little when I got home last night and tried this (VB.Net):
Dim X As Integer = 5
Dim Y As Integer = 3
Console.WriteLine("Hello World {1} {0}", X, Y)

And it printed this...
Hello World 3 5

So that pretty much answered my question...

This feature is needed for internationalization. The word order is often different in languages other than English. For example, in German, the noun-verb order is usually the opposite from English. By having the replaceable parameters be numbered, it allows you to take this into account.

On the original subject:

One of the benefits of the Try..Catch..Finally block is that it allows you to only catch the errors for which your code is equipped to handle. A database layer could catch all the database-related errors, while allowing others to continue on to other Catch blocks.

You'll want to have a Try..Catch block at the main entry point of user input to your code, just to make sure that you catch anything that might have slipped through (otherwise the user sees a "Unhandled Exception" error, which looks really unprofessional). You'd replace it with a generic "The application has generated an error" message, which is not that informative, at least looks better.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top