What is the difference between if/else and try/finally in C#?

Hi, I am very familiar with the if/else statements but less familiar with the try/finally statements.  I am wondering when I should use one versus the other?  What is the difference exactly?
FairyBusinessAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_davisCommented:
if else, as you know is a decision making statement

try/catch/finally is more of an error handling framework.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
They are two totally different, yet somewhat related concepts. p_davis has already noted the difference. The only thing I'd like to add is that you should prefer if/else over try/catch. What I mean by that is you should always try to write code which does not generate exceptions. Many conditions which cause exceptions can be tested for within your code (e.g. blank text boxes, integer overflows, null references, etc.). When you rely on 3rd-party APIs, then exception handling would be more convenient, because you have no idea what the code in the API is doing behind the scenes--after all, you didn't write it!
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

nishant joshiTechnology Development ConsultantCommented:
you might knowing one of the following language, are you?

 c,c++,java,sql,vb?

there is no difference in c# also .

try catch and if else usage are same for all languages..

regards..
0
käµfm³d 👽Commented:
C does not have try/catch.
0
FairyBusinessAuthor Commented:
the languages I know are as follows: html, css, javascript, php, and sql.  The try/catch/finally may be in other languages as well but I never used it before, and decided I might try to now.

thanks for the input guys!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.