473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

question from C# novice

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.
Nov 22 '05 #1
3 1295
SB
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.

Nov 22 '05 #2
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.


Nov 22 '05 #3
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.


Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
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...
4
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...
5
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...
21
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...
6
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...
3
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);
2
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...
3
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...
10
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...
49
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....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.