Bug 18849 - return statement in catch block hit even if not executed.
Summary: return statement in catch block hit even if not executed.
Status: RESOLVED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Debugger ()
Version: 1.10.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Vinicius Jarina
URL:
Depends on:
Blocks:
 
Reported: 2014-04-07 21:08 UTC by Jon Goldberger [MSFT]
Modified: 2016-05-10 17:03 UTC (History)
10 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test project (27.23 KB, application/zip)
2014-04-07 21:08 UTC, Jon Goldberger [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Comment 1 Jon Goldberger [MSFT] 2014-04-07 21:20:13 UTC
Running the test project in VS 2013 deploying to an iOS simulator, tried both iOS 6. and 7.1, a breakpoint set on the return statement in a catch block will be hit even if the return statement in the try block is executed.

Steps to reproduce:
1. Load and deploy the test project using VS 2013.
2. Press the Click Me button
3. Observe that the breakpoint on the return statement in the try block is hit.
4. Press continue.
5. Observe that the breakpoint in the catch block is also hit.
6. Press continue.
7. The value returned from the return statement in the try block is written to the console. 

In addition I noted that setting a breakpoint on any other statement in the catch block (put in a Console.WriteLine() statement to verify) is not hit, nor executed. 

Further I noted that if I also add a return statement at the end of the method,  one which there is no way to reach, and put a breakpoint on that return statement it is also hit after the other two breakpoints are hit. 

Note that code execution is correct and only the return statement in the try block is actually executed.

The same behavior does _not_ happen in Xamarin Studio on the Mac. In XS (on the Mac, did not check XS on the Windows machine), the breakpoints are hit as expected.

------------------------------------------------
My VS version info:

Microsoft Visual Studio Ultimate 2013
Version 12.0.21005.1 REL
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Ultimate

Architecture and Modeling Tools   06181-004-0451031-02209
Microsoft Architecture and Modeling Tools
    
UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.

LightSwitch for Visual Studio 2013   06181-004-0451031-02209
Microsoft LightSwitch for Visual Studio 2013

Microsoft Office Developer Tools for Visual Studio 2013 ENU   06181-004-0451031-02209
Microsoft Office Developer Tools for Visual Studio 2013 ENU

Team Explorer for Visual Studio 2013   06181-004-0451031-02209
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06181-004-0451031-02209
Microsoft Visual Basic 2013

Visual C# 2013   06181-004-0451031-02209
Microsoft Visual C# 2013

Visual C++ 2013   06181-004-0451031-02209
Microsoft Visual C++ 2013

Visual F# 2013   06181-004-0451031-02209
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06181-004-0451031-02209
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06181-004-0451031-02209
Windows Phone SDK 8.0 - ENU

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.0.11001.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.0
Provides common services for use by Azure Mobile Services and Windows Azure Tools.

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone
Build 

Microsoft Web Developer Tools 2013   2.0.40926.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Windows Azure Web Sites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Windows Azure

NuGet Package Manager   2.7.40911.287
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.30919.1
Microsoft SQL Server Data Tools

Windows Azure Mobile Services Tools   1.0
Windows Azure Mobile Services Tools

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin.Android   4.12.03003 (7f0e3d3c)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   1.10.47 (3d6a125d)
Visual Studio extension to enable development for Xamarin.iOS
Comment 4 Ram Chandra 2014-04-08 06:26:00 UTC
We have checked this issue with "attached project" and to reproduce this issue we have follow the steps provided in bug description and we are able to reproduce this issue.

Case 1: 
We observed that when we press the "Click Me" button on "iOS Simulator" the program control stops at break point which is in try block and then we press "Continue" on VS the program flow goes to catch block  but there is no any exception we are just returning a value from try block. To verify this we have checked that if there is an exception in the program and we have removed the try and catch block but application doesn't throw any exception. 

Result: Program flow goes to catch block  when there is not any exception.

Case 2 :
We also observed that when we put any line inside the catch block for example Console.WriteLine("Test"); (before the return statement)  and put a break point on the same line and run the program. The program control doesn't hit on that line which we have added.

Result: Program doesn't hit the "break point " inside the catch block except the return statement.

Case 3:
We have noticed one more thing that when the program control goes to catch block and return statement returns 43 but on output window it returns the value of try block i.e. 42. 

Case4: We tried to reproduce the following case but we are unable to reproduce this case. Our control flow doesn't hit the return statement which is added at the last of "Execute()" method.

"Further I noted that if I also add a return statement at the end of the method,  one which there is no way to reach, and put a breakpoint on that return statement it is also hit after the other two breakpoints are hit. "

Please let me know if I am missing anything to reproduce case4.

screencast: http://www.screencast.com/t/g1qQxyfjx

Environment Info: 

Windows 7
Visual Studio Professional 2013
Microsoft .NET Framework Version 4.5.50938
Xamarin.iOS 1.10.47(3d6a125d)
Comment 5 Jon Goldberger [MSFT] 2014-04-08 12:29:54 UTC
I made an error. For case 4, if you remove the return statement from the catch block and instead have one at the last line of the Execute() method, then a breakpoint on the last return statement will be hit. IOW:

1. breakpoint on return statement in try block.
2. No return statement or breakpoint in catch block.
3. breakpoint on return statement add to end of Execute() method.
4. Result: both breakpoints will be hit.
Comment 8 Jerome Laban 2014-05-06 08:19:43 UTC
@vinicius, what kind of information do you need ?

Thanks,
Comment 9 Sadik Ali 2015-07-15 08:57:49 UTC
I have tried this issue and unable to reproduce the reported behavior at my end.

Steps To Reproduce:
1.Download the application.
2.Run the application on Simulator.
3.Click on Button.
4.It will hit the breakpoint on try block.
5.Press on Continue.It does not hit the break point on catch block.

Screencast: http://www.screencast.com/t/wS6LuyrssC

As if now I am closing this issue.If you again getting the same behavior please feel free to reopen this issue.

Environment Info:

Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.6.00007

Installed Version: Professional

LightSwitch for Visual Studio 2013   06177-004-0446016-02589
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06177-004-0446016-02589
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06177-004-0446016-02589
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0446016-02589
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0446016-02589
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0446016-02589
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06177-004-0446016-02589
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.4.51016.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.21010.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.3
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Azure Mobile Services Tools   1.3
Microsoft Azure Mobile Services Tools

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.3
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Compact & SQLite Toolbox   4.1.0
SQL Server Compact & SQLite Toolbox adds scripting, import, export, rename, query execution and much more to SQL Server Compact & SQLite Data Connections.

SQL Server Data Tools   12.0.41012.0
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.11.666.0 (ebae43a)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   5.1.4.16 (5f55a9ef61c11b6ce0890bc91e4c71b1b92be214)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.Forms Intellisense   1.0
Provides intellisense for Xamarin.Forms in the XML editor.

Xamarin.iOS   8.10.2.0 (67b390d0d1bd741582cf7b7fd3ffea08583a3f83)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified

Xamarin.TestCloud.Integration   1.0
Early preview of Xamarin Test Cloud integration