Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 29th, 2004, 10:42 AM
Registered User
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to know when an exception occurs?

 Hi, first sorry for my bad english. I'm spanish and my english is very bad... Well, my question is:

I'm doing a logger in c# (for .NET Compact Framework) that not write a trace in file directly. The logger put the trace in a buffer, and when the buffer has at one particular size writes all traces in the file log.

The problem is when occurs a exception the buffer can have traces that
can not be write in the file because the buffer haven't the size appropiate.

How I know when an exception occurs if it's not controlled? Launch an event?
I try with a destructor in the class but not work.

Exists a class that can execute a method when a program exit?



Old December 29th, 2004, 06:21 PM
Kep Kep is offline
Authorized User
Join Date: Aug 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts

Why not place a try-catch in the Main method of your application? The catch could just write out the exception details and then re-throw the exception.

Old December 30th, 2004, 04:05 AM
Registered User
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

 I believe that my explication has been a little bad.

I want that the developer that uses the logger only call (for example) Logger.getLogger().entering("class","method",...) and he don't worry about nothing more. I don't want that the person at uses the logger have to catch the exception in his program for the correct operation of the logger.

I want that the logger knows when a exception has throw by any cause and then the logger write the rest of the buffer to the file.

I believe that when a exception throws, the garbage collector destroy the class but this not happen.

I'm looking for something like this:
In the constructor of the logger (the logger uses a singleton pattern for his creation), it registrates how listener of a event.
This event will be launch when a exception (anything exception) has throw in the source that uses the logger.
Then the looger at be registred like listener of this event can flush the buffer to the file.

I don't kwow if this can be possible or not.

Than you,


Similar Threads
Thread Thread Starter Forum Replies Last Post
XL VBA Compile - what occurs - why crash PCWeaver Excel VBA 0 September 13th, 2006 11:13 AM
How to handle error or exception if it occurs popoxinhxan BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 August 27th, 2006 06:44 PM
error occurs while uploading file to http://localh madhusrp ASP.NET 1.0 and 1.1 Professional 2 March 15th, 2006 11:41 AM
urgent: session timeout occurs unexpectedly seemagaur ASP.NET 1.0 and 1.1 Basics 0 October 10th, 2005 12:59 PM
Dangerous error occurs on topic and reply forms drfunkie BOOK: ASP.NET Website Programming Problem-Design-Solution 2 July 11th, 2003 09:00 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.