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...
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler (show other bugs)
Version: 4.20.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2015-01-08 04:07 UTC by Juro
Modified: 2015-01-08 15:54 UTC (History)
2 users (show)

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


Attachments

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()
		{
			aaa();
		}

		static void ccc()
		{
			try
			{
				bbb();
			}
			catch
			{
				throw;
			}
		}
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
Runtime:
	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: 8.6.0.50 (Business Edition)
Hash: 561dfed
Branch: 
Build date: 2015-01-06 17:56:14-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (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: 1.11.3.0 (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.

Note You need to log in before you can comment on or make changes to this bug.