Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7511411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:32:18+00:00 2026-05-29T23:32:18+00:00

Whats the differenc of using a variable inside the try section and the catch

  • 0

Whats the differenc of using a variable inside the try section and the catch section

string curNamespace;

try
{
  curNamespace = "name"; // Works fine
}
catch (Exception e)
{
// Shows use of unassigned local variable  
throw new Exception("Error reading " + curNamespace, e);

}

If i use variable inside try section it compiles fine, in catch section i get “Use of unassigned variable”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T23:32:19+00:00Added an answer on May 29, 2026 at 11:32 pm

    The compiler is complaining because you may encounter an exception before the value is initialized. Consider the following (very contrived) example:

    string curNamespace;
    try {
        throw new Exception("whoops");
    
        curNamespace = "name"; // never reaches this line
    }
    catch (Exception e) {
        // now curNamespace hasn't been assigned!
        throw new Exception("Error reading " + curNamespace, e);
    
    }
    

    The fix would be to initialize curNamespace to some default value outside the try..catch. Have to wonder what you’re trying to use it for, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the difference between using an environment variable, like PATH, as $PATH or
I'm using a string builder to build some SQL Scripts. I have a few
Couple questions. Whats the best way to access a live .db file using sqlite
There are various string formatting methods: Python <2.6: "Hello %s" % name Python 2.6+:
I'm trying to figure out how to use a defined variable when using <<<HTML
What is the difference in using object.variable and object->variable ? When should I use
What is the difference between a variable using declaration and a variable is declared
What's the difference between using a define statement and an enum statement in C/C++
What's the difference when using GET or POST method? Which one is more secure?
what's the difference between using a js library like jquery and using an ajax

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.