|
Hi. I'm trying to catch all unhandled exceptions in my application (so they can be logged and the user presented with a "nice" message instead of some confusing "computer-y" message.
I do the following in my WinForm application:
-- In the constructor
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(OverAllUnhandledHandler);
-- the method
static void OverAllUnhandledHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
logger.Log(LogLevel.Fatal, e.ToString());
MessageBox.Show("Please check error logs for details", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
If I create a divide by zero error, it is trapped (either in the constructor or in a button click event. I have even created a thread that starts and causes the error; it is still trapped. However, some errors are still popping up in the standard "Microsoft .NET Framework" dialog, with the text "An unhandled exception has occurred in your application.....".
Any idea how to get all unhandled exceptions (I know, code better to catch all exceptions) to be caught by this OverAllUnhandledHandler method?
Thanks for any tips.
--G
|
|
|
|
|
I put my main code in a try/catch and handle threaded exceptions, it's a long time since my app blew up without logging a nice error for me and telling the user of the same.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks -- haven't been handling threaded exceptions -- giving that a shot.
Do you mean you put a try/catch around the
Application.Run(formName); in Main() ?
|
|
|
|
|
Yes, that's all I did initially, then as I am multithreaded, I had to add code to handle exceptions in threads.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Great. Thanks. I've included both the try/catch and the ThreadException code -- we'll see how it runs this afternoon!
|
|
|
|
|
I handle exceptions using:
AppDomain.UnhandledException,
System.Windows.Forms.Application.ThreadException,
and a catch-all handler in void Main().
This gets all unhandled exceptions (well, except for some that are swallowed by Windows Forms/COM in the Drag* events - put catch handlers in all Drag* event handlers).
|
|
|
|
|
Thanks Daniel -- this is now how the application works (I previously only had AppDomain.UnhandledException, thinking that it would get all unhandled exceptions). Since I don't (currently) do any drag events, I should be OK (but I'll keep it in mind for future projects).
--G
|
|
|
|
|
Hi.
I have a DataGridView, now I want to use edit feature of it.
for save changes to DB, the way that I know is that read all rows of DataGridView and update all rows in DB (even rows that have no changes)
What is better way, that only changes be updated?
Best wishes
|
|
|
|
|
I use this in the CellLeave event to update the underlying dataAdapter. Before calling this however, I loop through the grid to ensure that no values being updated are going to throw up errors.
<br />
dataAdapter.Update(table);<br />
|
|
|
|
|
I hope that sounds right? I will explain...
I have built a class (lets call it 'X') that constructs a StringBuilder and then passes it back. All is OK except within this class it calls a number of methods from a base class higher up.
Here comes the tricky bit. Class 'Z' overrides a number of these base class methods, then calls 'X'.
There are also several versions of 'Z' each doing similar things but with subtle differences.
Question: Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...?
Thanks in advance,
Phil
"Rules are for the obedience of fools and the guidance of wise men"
|
|
|
|
|
Phillip Hodges wrote: Is there a way of calling the overridden methods in the parent class 'Z' from the child 'X'...?
Yes, just call them. If they are declared as virtual in the base class and override in the derived class then the correct version will be called. i.e. The version defined in the concrete class. That is to say the version of the real object, not its base.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Thanks for the quick response... Yeah, I made a silly mistake... It is working fine now...
Thanks again,
Phil
"Rules are for the obedience of fools and the guidance of wise men"
|
|
|
|
|
Phillip Hodges wrote: lets call it 'X'
Actually, lets not - it just complicates things and takes therm out of context. Im sure you use a descriptive name in your code (like MyStringCreator or something) so why not use it here to help people understand the context in which you are writing code.
|
|
|
|
|
I have a gridview that contains a checkbox for a user to select his choice.
I want a code that enables user to check all and uncheck the check box at ones
I am using ASP.net and C_sharp.
Please advice
|
|
|
|
|
You want to do this without postback ? You need to write javascript to do it in that case, which is a little involved, you need to get the id's of the input controls, so you can look them up and set their state.
BTW, you should ask in the ASP.NET forum, and only there.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks for your time. Yes ,its with out postack.Dont you think it can be done in cSharp.
Thanks
|
|
|
|
|
kibromg wrote: Dont you think it can be done in cSharp.
Of course not. Your C# code is not called unless you do a postback.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks Christian ,
I will try and get a javascript.
Best regards
|
|
|
|
|
|
1. I don't mean to be a snob, but English is the only language used here. I don't know why you started off in English and then lapsed into Spanish(?).
2. This looks like an SQL question. You're better off posting it in the right forum.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
As addressed before, please use English. Also, please give your message titles some meaning. Make sure you place your message in the correct forum.
______________________
stuff + cats = awesome
|
|
|
|
|
This is SQL 101, I recommend buying a book on SQL and working through it. Even the books online that come with SQL Server will cover this for you.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
you did show your message both in English and in Spanish.
There is nothing wrong with that.
As far as I am concerned, you can write in whatever language(s) you choose;
the fact remains you are most likely to get answers if English is used (also).
I am sorry you felt compelled to remove it.
|
|
|
|
|
Luc Pattyn wrote:
you did show your message both in English and in Spanish
Did he? I thought he started off in English and then went into Spanish.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
IIRC there where two English sentences, followed by their exact translation into
Spanish, then followed by a Spanish sentence saying "I would appreciate getting
an example" (my knowledge of Spanish is very limited, I did however recognize "ejemplo")
That one sentence was the only thing missing in the English version.
BTW: the forum guidelines (the first topic in the C# forum, by Chris)
as well as the article by Pete dont require you use English or English only.
Of course switching languages in the middle of a post would be a bad idea...
|
|
|
|