Wrox Programmer Forums
|
C# 4.0 aka C# 2010 General Discussion Discussions about the C# 4.0, C# 4, Visual C# 2010 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 4.0 aka C# 2010 General Discussion 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 May 21st, 2011, 11:24 AM
Friend of Wrox
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default Try and catch blocks.

Can you nest try blocks within other try blocks and then have catch blocks nested withing those different nested try blocks? Also on debuging I noticed that the page will sometimes go to the basepage.cs into the pre-render part of the webfolder. Why is this going on here?
 
Old May 21st, 2011, 11:42 AM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Yes, you can nest multiple try blocks:
Code:
try
{
   try
   {
   }
   catch (SomeException ex)
   {
   }
}
catch (SomeException ex)
{
}
Nesting of try blocks happen for example if you do a try/catch within method Foo, and method Bar invokes method Foo, and the Bar method has a try/catch as well.

What catch is taking over depends. For example, if a throw happens inside the inner try block first the inner catch gets a chance for catching the exception. If the exception type is different of the inner catch, the exception goes to the next outer try. If the exception is caught within the inner catch there's still a chance that the next outer catch continues if the inner catch re-throws the exeption.

Hope this helps,
Christian
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel





Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested Try blocks vbboyd BOOK: Beginning ASP.NET 4 : in C# and VB 5 May 21st, 2011 11:36 AM
Building Blocks terry s Dreamweaver (all versions) 1 August 16th, 2005 02:42 PM
The 7 application blocks EricJ General .NET 0 June 30th, 2005 06:57 AM
buildng blocks terry s Dreamweaver (all versions) 11 January 24th, 2005 02:57 PM





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