473,382 Members | 1,639 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,382 software developers and data experts.

C#/specification bug?

C# Language Specification 1.2 says:

<<Exceptions that occur during destructor execution are worth special
mention. If an exception occurs during destructor execution, and that
exception is not caught, then the execution of that destructor is terminated
and the destructor of the base class (if any) is called. If there is no base
class (as in the case of the object type) or if there is no base class
destructor, then the exception is discarded.>>
The exception does not seem to be discarded - the program terminates
abnormally whether B inherits A or not.

Cheers

---

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace cstest
{
class A
{
~A()
{
Console.WriteLine( "~A()" );
}
}

class B //: A
{
~B()
{
throw new Exception();
//Console.WriteLine( "~B()" );
}

public bool z = false;
}
class Program
{
static void Main( string[] args )
{
B b = new B();
b = null;
#if true
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine( "OK" );
#else
int length = 2;
for( int i = 0; ; i++ )
{
Thread.Sleep( 1000 );
byte[] bb = new byte[ length ];
length *= 2;
Console.WriteLine( "OK {0} {1}", i, bb.Length );
}
#endif
}
}
}
May 15 '07 #1
1 1489
It was/is true for .NET v1.1.
As of .NET 2.0 the exception will be propagated and kills the finalizer
thread.
And that will cause abnormal application termination.

"cristalink" <cr********@nospam.nospamha scritto nel messaggio
news:uY**************@TK2MSFTNGP04.phx.gbl...
C# Language Specification 1.2 says:

<<Exceptions that occur during destructor execution are worth special
mention. If an exception occurs during destructor execution, and that
exception is not caught, then the execution of that destructor is
terminated and the destructor of the base class (if any) is called. If
there is no base class (as in the case of the object type) or if there is
no base class destructor, then the exception is discarded.>>
The exception does not seem to be discarded - the program terminates
abnormally whether B inherits A or not.

Cheers

---

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace cstest
{
class A
{
~A()
{
Console.WriteLine( "~A()" );
}
}

class B //: A
{
~B()
{
throw new Exception();
//Console.WriteLine( "~B()" );
}

public bool z = false;
}
class Program
{
static void Main( string[] args )
{
B b = new B();
b = null;
#if true
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine( "OK" );
#else
int length = 2;
for( int i = 0; ; i++ )
{
Thread.Sleep( 1000 );
byte[] bb = new byte[ length ];
length *= 2;
Console.WriteLine( "OK {0} {1}", i, bb.Length );
}
#endif
}
}
}

May 15 '07 #2

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

Similar topics

6
by: Patrick | last post by:
Hi I am a newbie struggling a little with css.It is hard to get it right in all browsers, so i decided to read the CSS2 specification on the w3 site. What is the following from the CSS2...
2
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from...
1
by: B.Desai | last post by:
Hello Experts, Can you please help me out? I am very frustrated! I am trying to update import specification, and it does not let me do that. I have saved specification and now I need to add...
4
by: carrionk | last post by:
Hi, I'm exporting data from MSAccess to a *.txt file using VBA. I have already set up specification to TAB delimited, no Commas for Text and saved it ( .. in File>Export, etc) The problem is...
2
by: Mike Schilling | last post by:
Is there an official specification for .NET serialization? I've looked at the .NET framework docs and read Jeffrey Richter's MSDN articles, but I'm looking for something more complete,...
6
by: Tony Whitter | last post by:
Does anyone know how much changed between the final draft dated October 2002 and the Ecma-334 C# Language Specification 2nd edition dated December 2002 and if there is a change history document...
0
by: Marshal [DirectX MVP 2003] | last post by:
In anticipation of the chat, I have filtered all of my current enhancement aleration ideas through the software development community, via the following postings: C# Language Specification -...
7
by: forgroupsonly | last post by:
Hello All. I wonder if browsers developers scoff at CSS developers... I do simple tests while reading CSS2.1 specification, just few boxes. And from time to time I see that recent browsers...
2
by: MIG | last post by:
I am aware that when importing a file it's possible to save a specification that says, for example, treat a particular field as text, whenever importing a file of exactly the same format. It's...
11
by: George2 | last post by:
Hello everyone, How do you understand the Bjarne's comments about exception specification? Especially, "not required to be checked across compilation-unit" and "violations will not be caught...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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 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.