Click here to Skip to main content
15,896,269 members
Home / Discussions / C#
   

C#

 
GeneralRe: a try inside another Pin
Rick van Woudenberg3-May-11 1:57
Rick van Woudenberg3-May-11 1:57 
GeneralRe: a try inside another Pin
J4amieC3-May-11 3:00
J4amieC3-May-11 3:00 
GeneralRe: a try inside another Pin
Rick van Woudenberg3-May-11 4:14
Rick van Woudenberg3-May-11 4:14 
GeneralRe: a try inside another Pin
J4amieC3-May-11 4:36
J4amieC3-May-11 4:36 
GeneralRe: a try inside another Pin
BobJanova3-May-11 4:44
BobJanova3-May-11 4:44 
GeneralRe: a try inside another Pin
J4amieC3-May-11 4:50
J4amieC3-May-11 4:50 
GeneralRe: a try inside another Pin
Pete O'Hanlon3-May-11 5:41
mvePete O'Hanlon3-May-11 5:41 
GeneralRe: a try inside another Pin
Rick van Woudenberg3-May-11 23:52
Rick van Woudenberg3-May-11 23:52 
GeneralRe: a try inside another Pin
Gary Wheeler4-May-11 0:44
Gary Wheeler4-May-11 0:44 
GeneralRe: a try inside another Pin
DragonLord664-May-11 6:56
DragonLord664-May-11 6:56 
GeneralRe: a try inside another Pin
Pete O'Hanlon4-May-11 7:03
mvePete O'Hanlon4-May-11 7:03 
JokeRe: a try inside another Pin
DragonLord664-May-11 7:11
DragonLord664-May-11 7:11 
GeneralRe: a try inside another Pin
Pete O'Hanlon4-May-11 8:04
mvePete O'Hanlon4-May-11 8:04 
GeneralRe: a try inside another Pin
DragonLord664-May-11 8:06
DragonLord664-May-11 8:06 
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 

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.