Bug 6315 - debugger fails to catch arbitrary exception through signal event handler
Summary: debugger fails to catch arbitrary exception through signal event handler
Status: CONFIRMED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Debugger (show other bugs)
Version: Trunk
Hardware: All All
: Low enhancement
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-07-27 23:26 UTC by Atsushi Eno
Modified: 2017-08-04 22:30 UTC (History)
1 user (show)

Tags:
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 6315 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:
Status:
CONFIRMED

Description Atsushi Eno 2012-07-27 23:26:04 UTC
With the simple code below, I cannot get the debugger catch the NRE at "button_Clicked" method:

using System;
using Gtk;

namespace uitest
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			Application.Init ();
			
			var win = new Window (WindowType.Toplevel){
				DefaultWidth = 400,
				DefaultHeight = 300
			};
			win.DeleteEvent += (sender, e) => {
				Application.Quit ();
				e.RetVal = true;
			};
			
			var button = new Button("test");
			button.Clicked += button_Clicked;
			win.Add (button);
			
			win.ShowAll ();
			Application.Run ();
		}
		
		static void button_Clicked (object sender, EventArgs e)
		{
			string s = null;
			s.ToString (); // null reference exception
		}
	}
}

This *should* raise an error, but the problem is the debugger cannot catch that. I can set a breakpoint to "string s = null;" line, so the debugger can stop it. (This may be rather an sdb issue, I'm not sure.)

Marshaling clicked signal
Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
  at uitest.MainClass.button_Clicked (System.Object sender, System.EventArgs e) [0x00003] in /home/atsushi/Projects/ConsoleApp3/ConsoleApp3/Main.cs:33 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d5] in /svn/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:229 
  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000eb] in /svn/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:237 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /svn/mono/mcs/class/corlib/System.Reflection/MethodBase.cs:101 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e4] in /svn/mono/mcs/class/corlib/System/Delegate.cs:424 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00018] in /svn/mono/mcs/class/corlib/System/MulticastDelegate.cs:72 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /svn/mono/mcs/class/corlib/System/Delegate.cs:398 
  at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00050] in /svn/gtk-sharp/glib/Signal.cs:195 
  at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00011] in /svn/gtk-sharp/glib/SignalClosure.cs:118 
  at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x0007d] in /svn/gtk-sharp/glib/SignalClosure.cs:146 
   at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal) in /svn/gtk-sharp/glib/ExceptionManager.cs:line 58
   at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) in /svn/gtk-sharp/glib/SignalClosure.cs:line 173
   at Gtk.Application.gtk_main()
   at Gtk.Application.Run() in /svn/gtk-sharp/gtk/Application.cs:line 135
   at uitest.MainClass.Main(System.String[] args) in /home/atsushi/Projects/ConsoleApp3/ConsoleApp3/Main.cs:line 27
Comment 1 Jeffrey Stedfast 2013-04-01 14:52:05 UTC
The problem is that Gtk# has its own unhandled exception handling around user event handlers which it catches (and so the runtime can't know that it was "unhandled").

GLib catches it, and if the user hasn't attached their own unhandled exception handler, it prints the stack trace and exits.

You could use the Catchpoints feature in Xamarin Studio to catch these before they get caught by Gtk#'s code.