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?
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.

if else, as you know is a decision making statement

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

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
kaufmed 👽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!
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

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


there is no difference in c# also .

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

kaufmed 👽Commented:
C does not have try/catch.
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!
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

From novice to tech pro — start learning today.