When I try to compile the code below I receive a first chance exception. I've
noticed from searching on the web that some people choose to ignore first
chance exceptions. Is this common practice? Do you guys see anything wrong
with my code or should I ignore the exception it generates?
<Using directives here>
namespace Settings
{
enum DisplacementUnits { Feet, Kilofeet, Meters, Kilometers, NauticalMiles };
abstract class Variable
{
public abstract int Unit
{
get;
set;
}
public double Value //Using another name doesn't help
{
get
{
return Value;
}
set
{
Value = value; //Generates a A first chance exception of type
'System.StackOverflowException'
}
}
}
class DisplacementVariable : Variable
{
public override int Unit
{
get
{
return Unit;
}
set
{
Console.WriteLine("set");
}
}
public DisplacementVariable()
{
Unit = (int)DisplacementUnits.Feet;
Value = 0;
}
public DisplacementVariable(double value, int unit)
{
Unit = unit;
Value = value;
}
}
class Settings
{
double someVar1;
string someVar2;
static void Main(string[] args)
{
DisplacementVariable x = new DisplacementVariable(0,0);
Console.WriteLine("in main..");
Console.ReadLine();
}
}
}
I'm using VS2005 beta1. 3 1298
Your problem is that inside your setter, you are calling your setter
again....which will cause a stack overflow as you have seen :) Where is
your variable to hold Value? That is what you should be setting/getting.
HTH,
-sb
"Jose" <Jo**@discussions.microsoft.com> wrote in message
news:BE**********************************@microsof t.com... When I try to compile the code below I receive a first chance exception. I've noticed from searching on the web that some people choose to ignore first chance exceptions. Is this common practice? Do you guys see anything wrong with my code or should I ignore the exception it generates?
<Using directives here> namespace Settings {
enum DisplacementUnits { Feet, Kilofeet, Meters, Kilometers, NauticalMiles };
abstract class Variable { public abstract int Unit { get; set; } public double Value //Using another name doesn't help { get { return Value; } set { Value = value; //Generates a A first chance exception of type 'System.StackOverflowException' }
} }
class DisplacementVariable : Variable { public override int Unit { get { return Unit; } set { Console.WriteLine("set"); } }
public DisplacementVariable() { Unit = (int)DisplacementUnits.Feet; Value = 0; } public DisplacementVariable(double value, int unit) { Unit = unit; Value = value; } }
class Settings { double someVar1; string someVar2;
static void Main(string[] args) { DisplacementVariable x = new DisplacementVariable(0,0); Console.WriteLine("in main.."); Console.ReadLine(); } } }
I'm using VS2005 beta1.
I'm confused - are you saying that I can't have a variable named Value? I
know "value" is a special word but I didn't know that Value was also reserved.
"SB" wrote: Your problem is that inside your setter, you are calling your setter again....which will cause a stack overflow as you have seen :) Where is your variable to hold Value? That is what you should be setting/getting.
HTH, -sb
"Jose" <Jo**@discussions.microsoft.com> wrote in message news:BE**********************************@microsof t.com... When I try to compile the code below I receive a first chance exception. I've noticed from searching on the web that some people choose to ignore first chance exceptions. Is this common practice? Do you guys see anything wrong with my code or should I ignore the exception it generates?
<Using directives here> namespace Settings {
enum DisplacementUnits { Feet, Kilofeet, Meters, Kilometers, NauticalMiles };
abstract class Variable { public abstract int Unit { get; set; } public double Value //Using another name doesn't help { get { return Value; } set { Value = value; //Generates a A first chance exception of type 'System.StackOverflowException' }
} }
class DisplacementVariable : Variable { public override int Unit { get { return Unit; } set { Console.WriteLine("set"); } }
public DisplacementVariable() { Unit = (int)DisplacementUnits.Feet; Value = 0; } public DisplacementVariable(double value, int unit) { Unit = unit; Value = value; } }
class Settings { double someVar1; string someVar2;
static void Main(string[] args) { DisplacementVariable x = new DisplacementVariable(0,0); Console.WriteLine("in main.."); Console.ReadLine(); } } }
I'm using VS2005 beta1.
public double Value //Using another name doesn't help
{
get
{
return Value;
}
set
{
Value = value; // Calls itself until it crashes...
}
Generally the get/set just updates a private variable. Here you are using
the name of the property that is you are calling again the "set" that calls
again the "set" and so on until it crashes...
Patrice
-
"Jose" <Jo**@discussions.microsoft.com> a écrit dans le message de
news:8F**********************************@microsof t.com... I'm confused - are you saying that I can't have a variable named Value? I know "value" is a special word but I didn't know that Value was also
reserved. "SB" wrote:
Your problem is that inside your setter, you are calling your setter again....which will cause a stack overflow as you have seen :) Where
is your variable to hold Value? That is what you should be
setting/getting. HTH, -sb
"Jose" <Jo**@discussions.microsoft.com> wrote in message news:BE**********************************@microsof t.com... When I try to compile the code below I receive a first chance
exception. I've noticed from searching on the web that some people choose to ignore
first chance exceptions. Is this common practice? Do you guys see anything
wrong with my code or should I ignore the exception it generates?
<Using directives here> namespace Settings {
enum DisplacementUnits { Feet, Kilofeet, Meters, Kilometers, NauticalMiles };
abstract class Variable { public abstract int Unit { get; set; } public double Value //Using another name doesn't help { get { return Value; } set { Value = value; //Generates a A first chance exception of type 'System.StackOverflowException' }
} }
class DisplacementVariable : Variable { public override int Unit { get { return Unit; } set { Console.WriteLine("set"); } }
public DisplacementVariable() { Unit = (int)DisplacementUnits.Feet; Value = 0; } public DisplacementVariable(double value, int unit) { Unit = unit; Value = value; } }
class Settings { double someVar1; string someVar2;
static void Main(string[] args) { DisplacementVariable x = new DisplacementVariable(0,0); Console.WriteLine("in main.."); Console.ReadLine(); } } }
I'm using VS2005 beta1. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christopher Richards |
last post by:
It is possible to be able to receive email alerts (say, from Google News)
and publish them to a web page automatically?
I am a novice as far as PHP goes, but I can open and write to a file and...
|
by: Larry Chen |
last post by:
Hi,
I want to do the following:
declare a file stream and a writer in subroutine A
and perform the actual write operation in subroutine B.
How should I do it ?
( I believe this should be...
|
by: Marian |
last post by:
Hi,
I am totaly novice in .NET and I am studying a book about this. There
was mentioned "assembly". I did not understand, how function does it has .
I would like to know the exact run of code...
|
by: AES/newspost |
last post by:
My understanding -- I'm not an expert -- is that on (some? many? all?)
standard Internet servers a URL can point to a subdirectory name
followed by a backslash, and that links to this URL will...
|
by: ronwer |
last post by:
Hello,
The title doesn't completely cover the question I have, but it's a bit more
complicated problem we have.
We are using a database, based on Acces, but developed by a third party...
|
by: herrcho |
last post by:
Here is the code..
#define NAME "MEGATHINK, INC"
#define ADDRESS "10 Megabuck Plaza"
#define PLACE "Megapolis, CA 94904"
int main()
{
starbar();
printf("%s\n",NAME);
|
by: Dmitry Sazonov |
last post by:
I'm novice here and I'm sorry for stupid question. We are trying to
understand web services architecture, is it better than TIBCO.Randevouz and
does webservices fit our needs.
I understand, I...
|
by: Darius |
last post by:
Hello,
there is an NMEAParserDemo application written in VC++ avaliable for
download from
http://www.visualgps.net/Papers/NMEAParser/NMEAParserDemo%20Project.zip.
Source code in VC++ is...
|
by: dtmfcc |
last post by:
My website is at www.simi-therapy.com
My CSS is at http://www.simi-therapy.com/simitherapy-screen.css
Question -- on the dark blue bar under the beach image, one change
caused another...
|
by: Pilcrow |
last post by:
In the code below, can someone explain why the asterisks seem to be
required on the line labelled 'A' and forbidden on the line labelled
'B'?
Thanks in advance for the help....
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |