Click here to Skip to main content
15,901,373 members
Home / Discussions / C#
   

C#

 
AnswerRe: c# windows application Pin
OriginalGriff4-Jan-10 23:08
mveOriginalGriff4-Jan-10 23:08 
GeneralRe: c# windows application Pin
naghoumeh144-Jan-10 23:21
naghoumeh144-Jan-10 23:21 
GeneralRe: c# windows application Pin
OriginalGriff4-Jan-10 23:38
mveOriginalGriff4-Jan-10 23:38 
GeneralRe: c# windows application Pin
naghoumeh144-Jan-10 23:46
naghoumeh144-Jan-10 23:46 
GeneralRe: c# windows application Pin
OriginalGriff5-Jan-10 0:00
mveOriginalGriff5-Jan-10 0:00 
AnswerRe: c# windows application Pin
Programm3r4-Jan-10 23:12
Programm3r4-Jan-10 23:12 
AnswerRe: c# windows application Pin
Isaac Gordon6-Jan-10 1:25
Isaac Gordon6-Jan-10 1:25 
QuestionException context in C# Pin
Antoine Jaussoin4-Jan-10 22:51
Antoine Jaussoin4-Jan-10 22:51 
Hi!

I have a tricky question regarding exceptions in C#:

I need to know, somewhere in my code, if an execption has been thrown or not.

Basically, in the code below, when an unhandled exception is thrown within my using statement, the code will first call the Dispose() method on my UnitOfWork object (the one in the "using"), and THEN go in the catch statement. Wich is exactly what I want.

The only problem is, in my Dispose() method, I have no way to know if I'm there because of an exception (in that case I want to call some rollback code), or if I'm there because the code in the "using" ran ok.

My question is: how can I know if I'm in an error context from within my Dispose() method?

A few things you need to know:
- I'm working on a WinForm (so I can't use the ASP.NET Server.GetLastError())
- I can't use the event UnhandledException (as it can be handled externaly to my using statement, as showb below)
- I basicaly need the equivalent of Server.GetLastError(), but in WinForm...

<br />
try<br />
{<br />
<br />
    //This using will create a Unit Of Work, and Dispose it at the end<br />
    using (Dao.GetUnitOfWork())<br />
    {<br />
        throw new Exception("Wanted Exception");<br />
    } // Here my UnitOfWork will call Dispose()<br />
}<br />
catch<br />
{<br />
    //We swallow the exception for testing purpose<br />
}<br />


Thanks!!!

Antoine
AnswerRe: Exception context in C# Pin
Nicholas Butler4-Jan-10 23:20
sitebuilderNicholas Butler4-Jan-10 23:20 
GeneralRe: Exception context in C# Pin
Antoine Jaussoin5-Jan-10 0:10
Antoine Jaussoin5-Jan-10 0:10 
GeneralRe: Exception context in C# Pin
Nicholas Butler5-Jan-10 0:30
sitebuilderNicholas Butler5-Jan-10 0:30 
GeneralRe: Exception context in C# Pin
Antoine Jaussoin5-Jan-10 1:21
Antoine Jaussoin5-Jan-10 1:21 
GeneralRe: Exception context in C# Pin
Nicholas Butler5-Jan-10 1:35
sitebuilderNicholas Butler5-Jan-10 1:35 
GeneralRe: Exception context in C# Pin
Luc Pattyn5-Jan-10 2:26
sitebuilderLuc Pattyn5-Jan-10 2:26 
QuestionEnumerate eventlog sources Pin
Sunil G4-Jan-10 22:02
Sunil G4-Jan-10 22:02 
AnswerRe: Enumerate eventlog sources Pin
Programm3r4-Jan-10 23:19
Programm3r4-Jan-10 23:19 
AnswerRe: Enumerate eventlog sources Pin
Programm3r4-Jan-10 23:31
Programm3r4-Jan-10 23:31 
GeneralRe: Enumerate eventlog sources Pin
Sunil G5-Jan-10 1:31
Sunil G5-Jan-10 1:31 
QuestionC# Avr Pin
jojoba20104-Jan-10 21:30
jojoba20104-Jan-10 21:30 
AnswerRe: C# Avr Pin
OriginalGriff4-Jan-10 21:56
mveOriginalGriff4-Jan-10 21:56 
QuestionRe: C# Avr Pin
jojoba20104-Jan-10 22:00
jojoba20104-Jan-10 22:00 
AnswerRe: C# Avr Pin
OriginalGriff4-Jan-10 22:15
mveOriginalGriff4-Jan-10 22:15 
AnswerRe: C# Avr Pin
Luc Pattyn5-Jan-10 2:32
sitebuilderLuc Pattyn5-Jan-10 2:32 
QuestionHelp Pin
levan omadze4-Jan-10 20:58
levan omadze4-Jan-10 20:58 
AnswerRe: Help Pin
0x3c04-Jan-10 21:11
0x3c04-Jan-10 21:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.