Bug 25818 - Re-throwing the exception from catch block will cut off previous callstack info in Release build
Summary: Re-throwing the exception from catch block will cut off previous callstack in...
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.20.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2015-01-08 04:07 UTC by Juro
Modified: 2015-01-08 15:54 UTC (History)
2 users (show)

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

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 for Bug 25818 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Juro 2015-01-08 04:07:16 UTC
After upgrading Xamarin Android from 4.12.1 to 4.20, we are loosing the callstack info for unhandled exceptions. It only happens in Release build (Debug build shows whole callstack). Try following code:
		static void aaa()
			throw new Exception("Test");

		static void bbb()

		static void ccc()
Calling ccc(); will crash and prints out the whole callstack (aaa/bbb/ccc) in Debug, but it only prints ccc in Release. It relates to all exceptions re-thrown from catch block.
It does not happen with Xamarin Android 4.12.1.
Comment 1 Atin 2015-01-08 06:09:33 UTC
I have checked this issue and able to reproduce this. To reproduce this issue I have followed the steps mentioned below:

1. Create an android application in XS.
2. Open MainActivity.cs file and paste the above code in this class.
3. Call ccc(); method at clcick event of button.
4. Build app, set configuration to Release, deploy it on emulator.
5. Application will deploy , click on button.
6. Observed that exception will not show in call stack.

I also observed that when user call ccc(); it crash and prints out the whole call stack  in Debug mode.

Screencast: http://www.screencast.com/t/y8cJYn7D
Application Output: https://gist.github.com/Rajneesh360Logica/21bb265d3a27daf60e61
Build Output: https://gist.github.com/Rajneesh360Logica/2afe653b38d77dcad9c4
XS Logs: http://www.screencast.com/t/PziY4wpg

Environment Info:

=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
	Mono 3.12.0 ((detached/1538a59)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000072

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 561dfed
Build date: 2015-01-06 17:56:14-0500

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 2 Juro 2015-01-08 06:23:45 UTC
I have further inspected this issue (trying to find the workaround) and it seems that the problem isn't in the re-throwing itself but the callstack is lost before the catch block is executed:

catch (Exception e)
    Print(e.ToString()); // the callstack is lost even here

the finally block looses the callstack too (even if it is empty).

There is no way to make it work.
We are observing bug-reports with incomplete callstack. That's really bad. And the downgrade isn't possible due to the missing Lollipop compatibility.

The funny thing is that when I'm running the Release build under debugger, the callstacks are fine.
Comment 3 Juro 2015-01-08 15:54:48 UTC
Please forget my sample, it looses the callstack due to the compiler optimization. I'm sorry.

However, there is really a problem with the throw; statement.

In version 4.12.1, the rethrown exception contained full callstack, while in 4.20, it contains only a part of callstack from the exception point to the first catch block.
It is often in the low-layer library and we don't see who called it. Underlying callstack is lost.

It happens also in Debug and I am afraid (but not sure) that it also relates to iOS, where it behaves this way for a longer time.