473,382 Members | 1,386 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.

Exception Handling and Garbage Collection

a.. In Java, GC.Collect schedules the collection. As far as I know, in
..NET, it runs immediately after calling the method. Is that right?
b.. Should I use exception handling (try-catch) to avoid inconsistencies
that can occur in the Dispose method? For example, a connection is closed,
and then an error occurs and GC.SuppressFinalize is not executed. When GC
runs, it tries to close the connection again by calling the Dispose method
from Finalize.
c.. Is there a CATCH WHEN in C# to catch errors raised by a COM component
(err.raise)?
thanks again.
Nov 13 '05 #1
1 3985
Hi Marcelo,

a) GC.Collect requests that a garbage collection is executed, but that's not
guaranteed. For example, if the GC is in the middle of a collection when
GC.Collect is called, it won't be executed again. Also, calling GC.Collect
is normally a bad practice, because the GC has a much better understanding
of the local environment.

b) Yes, I use Try...Catch to handle problems within my Dispose methods (and
also in my Finalize methods).

c) No, CATCH WHEN... is a trick reserved for VB .NET.

HTH,

Mark
--
Author of "Comprehensive VB .NET Debugging"
http://www.apress.com/book/bookDisplay.html?bID=128
"J. Marcelo Barbieri" <mb*******@bf.com.br> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
a.. In Java, GC.Collect schedules the collection. As far as I know, in
..NET, it runs immediately after calling the method. Is that right?
b.. Should I use exception handling (try-catch) to avoid inconsistencies
that can occur in the Dispose method? For example, a connection is closed,
and then an error occurs and GC.SuppressFinalize is not executed. When GC
runs, it tries to close the connection again by calling the Dispose method
from Finalize.
c.. Is there a CATCH WHEN in C# to catch errors raised by a COM component
(err.raise)?
thanks again.

Nov 13 '05 #2

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

Similar topics

0
by: Jaime Wyant | last post by:
I've found that the code below will crash if I don't have the PyErr_Clear() function call. Should I always call PyErr_Clear()? The error message I get has to do with garbage collection --> ...
4
by: Joe Peterson | last post by:
I could not find another example of this via internet searches, so here it is... I am wondering if this is a python bug or otherwise. The first example of this happened in a larger program of...
3
by: Tony Johansson | last post by:
Hello Experts! Assume foo is a method in a some class or a stand-alone function and method push is throwing an exception of class logic_error. Assume also that I want to handle this exception in...
3
by: brobigi | last post by:
well I manage to figure it out myself. I'm using Bloodshed Dev-cpp Here's the code: #include "python.h" #include <stdio.h> int main(int argc, char* argv) { double answer = 0;
5
by: Karl | last post by:
Hi, I have some code that will save the contents of a Rich Text Box in either a Text or Rich Text Format file. The code is using the SaveFileDialog and is working correctly. I have been...
1
by: bw | last post by:
I have a basic custom collection that throws a new exception if the item(key) is not found in the collection. This is used as part of a calling function. It all works correctly, the problem...
3
by: dhussong | last post by:
I'm trying to implement a generic exception handling routine that will write information to a text file at the time the exception occurred. I am using the Microsoft Application Block for Exception...
29
by: v4vijayakumar | last post by:
Why there is no overloading (function and operator), function templates and exception handling support in c? after all these are all useful programming constructs. What prevents ANSI/ISO...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.