debug within try/catch VS2008

I'm facing a strange behaviour with the debugger of VS2008.

Looks that the debugger cannot see the variables defined inside a try/catch block

My code is something like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class A
{
public:
	A(): a_(1.) {}
	double f();
	double g();
	double a_;
};

double A::f()
{
	double b = 2.;
	try {
		double a = 3.;
		a += g();
		b = a + a_;
		//[...]
		return b;
	} catch (...) {
		//[...]
	}
	return b;
}
double A::g()
{
	double x = 5.;
	return x;
}


The code is executed correctly, but when I debug f() breaking just before the catch I cannot see in a watch window the value of the variable a. Instead, I can see a_ (class member) and b (defined outside the try/catch block). I can also see x if I go inside g().

I've never had this problem with VS2005.
Dou you have any idea of what it's happening?

Thank you very much,
dsil
Last edited on
Well to start with you need to set the accessability of your class, like:

1
2
3
4
5
6
7
8
9
10
class A
{
public:
	A(): a_(1.) {}
	double f();
	double g();

private:
	double a_;
};


So that we can actually test it.

Then, when you debug the code you will find that your debugger will only be aware of the variable 'a' inside the try...catch block as it is only declared within that block i.e. it doesn't exist outside. If you are using Visual Studio you will be able to see the values of variables in the 'Autos' 'Locals' windows the 'Watch' window will only show you the values of variables that are both currently in scope and that you have specified you want to watch.

HTH
Of course ajh32
(thank you for replying)
this is a very simplified code, as an example of a more general problem.

Think that A is a struct, or else that there is a public. I just edited the code adding the public keyword.

My problem is that if I put a breakpoint at line 18 I should see the value of a, a_ and b, instead I cannot see a.
In the watch window, where I put a, I read
CXX0017:Error:symbol a not found
Well, if I do exactly the same albeit in VS2010, put a breakpoint at line 18 I see the following in my watch window for a, a_, and b:

a : 8.0000000000000000
a_ : 1.0000000000000000
b : 9.0000000000000000

So, don't know why you are having this issue!
That's why I say it's strange...
I really don't know how to investigate the origin of the issue.

Maybe some debugging configuration?
Maybe something related with x64 application? I see that there are other issues about debugging a x64 application in VS2008, for exampe Edit&Continue is not supported.

I'm really confused...
If you are using the release mode, some symbols are taken away for optimization. Also as you just wrote, x64 functionalities aren't of the best.
Topic archived. No new replies allowed.