Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
GeneralRe: a try inside another Pin
James Lonero4-May-11 12:35
James Lonero4-May-11 12:35 
GeneralRe: a try inside another Pin
V.3-May-11 3:55
professionalV.3-May-11 3:55 
GeneralRe: a try inside another Pin
Pete O'Hanlon3-May-11 4:03
mvePete O'Hanlon3-May-11 4:03 
AnswerRe: a try inside another Pin
Luc Pattyn3-May-11 1:11
sitebuilderLuc Pattyn3-May-11 1:11 
GeneralRe: a try inside another Pin
Ali Al Omairi(Abu AlHassan)3-May-11 1:26
professionalAli Al Omairi(Abu AlHassan)3-May-11 1:26 
GeneralRe: a try inside another Pin
Rick van Woudenberg3-May-11 1:38
Rick van Woudenberg3-May-11 1:38 
GeneralRe: a try inside another Pin
Luc Pattyn3-May-11 2:17
sitebuilderLuc Pattyn3-May-11 2:17 
AnswerRe: a try inside another Pin
BobJanova3-May-11 1:12
BobJanova3-May-11 1:12 
A catch block containing nothing but a rethrow is by definition pointless. That is,
try {
 doStuff();
} catch {
 throw;
}

... is equivalent to simply calling doStuff(). So, if you haven't simplified out some code from the catch block, the outer try is pointless.

However, in the general case, this type of construct can be useful, because of the order of operations. In your example, if an exception is thrown, code is executed in the order inner-try, finally, catch, which means that the exception handler is called after the finally has been called and cleaned up. In a standard try { ... } catch { ... } finally { ... }, the order is try, catch, finally, so exception handlers are called before cleanup. If your exception handler is logging, aborting execution or calling something which assumes that the data is in a good state, the former can be better.

Edit: also, Luc makes a good point, if the finally code throws an exception, this structure will catch it, though finally code should not throw exceptions unless it is truly unavoidable.
AnswerRe: a try inside another Pin
PIEBALDconsult3-May-11 3:09
mvePIEBALDconsult3-May-11 3:09 
GeneralRe: a try inside another Pin
Luc Pattyn3-May-11 3:26
sitebuilderLuc Pattyn3-May-11 3:26 
GeneralRe: a try inside another Pin
PIEBALDconsult3-May-11 15:05
mvePIEBALDconsult3-May-11 15:05 
GeneralRe: a try inside another Pin
Luc Pattyn3-May-11 15:19
sitebuilderLuc Pattyn3-May-11 15:19 
GeneralRe: a try inside another Pin
PIEBALDconsult3-May-11 15:29
mvePIEBALDconsult3-May-11 15:29 
GeneralRe: a try inside another Pin
Jan Holst Jensen23-May-11 22:25
Jan Holst Jensen23-May-11 22:25 
GeneralRe: a try inside another Pin
PIEBALDconsult4-May-11 1:34
mvePIEBALDconsult4-May-11 1:34 
GeneralRe: a try inside another Pin
Jan Holst Jensen24-May-11 1:47
Jan Holst Jensen24-May-11 1:47 
AnswerRe: a try inside another Pin
patbob4-May-11 8:08
patbob4-May-11 8:08 
AnswerRe: a try inside another Pin
SilimSayo5-May-11 7:44
SilimSayo5-May-11 7:44 
AnswerRe: a try inside another Pin
Sandy_L_Schultz5-May-11 8:01
Sandy_L_Schultz5-May-11 8:01 
QuestionCrystal Report Pin
coolboos2-May-11 23:07
coolboos2-May-11 23:07 
AnswerRe: Crystal Report Pin
sund7wells2-May-11 23:53
sund7wells2-May-11 23:53 
AnswerRe: Crystal Report Pin
thatraja3-May-11 2:40
professionalthatraja3-May-11 2:40 
QuestionHow to input class name by user? Pin
wjbjnr2-May-11 22:32
wjbjnr2-May-11 22:32 
AnswerRe: How to input class name by user? [modified] Pin
Steven.Pinto20002-May-11 23:35
Steven.Pinto20002-May-11 23:35 
GeneralRe: How to input class name by user? Pin
wjbjnr6-May-11 3:08
wjbjnr6-May-11 3:08 

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.