Exception handlig with own plugins.


I am creating a tool window using the code below. Surprisingly, when there is an exception in my user control, visual studio crashes. (I am using resharper 5 eap beta)
Why is my exception not caught by 'resharper'' and displayed with resharper's default exception dialog? How can I change my code such that my exceptions are catched by resharper?

And another question is that with resharper 4.5 I could add a 'form' as a control to an ToolWindowContent. With resharper 5 beta  I get an exception. Is this by design or will this be fixed ?
best,
Joe

[assembly: ToolWindowDescriptor(ToolWindowVisibilityPersistenceScope = ToolWindowVisibilityPersistenceScope.SOLUTION,  Guid = "8CC73FC8-312C-4f1c-837A-2ED56D5D59F4", Text = "Foo text...", Id = "myTestWindow")]


[ActionHandler("MyPlugin.TestAction")]
public class MyActionHandler: IActionHandler {
  public bool Update(IDataContext context, ActionPresentation presentation, DelegateUpdate nextUpdate) {
      return true;
  }

  public MyActionHandler() {
            
  }

  private MyControl control = null;

  public void Execute(IDataContext context, DelegateExecute nextExecute) {
           
      if (control == null) {
          control = new MyControl ();
          IToolWindowFrame frame = WindowManager.Instance.GetToolWindowFrame("myTestWindow");
          IToolWindowContent tw = new ToolWindowContent(control, "Tool Window Test title");
          frame.Content = tw;                
          tw.Control.BackColor = SystemColors.Control;             
          DaemonStage.Control = control;
      }            
      IToolWindowFrame frame = WindowManager.Instance.GetToolWindowFrame("myTestWindow");
      frame.Show();
  }
}

public partial class MyControl : UserControl {

  private void toolStripButton2_Click(object sender, EventArgs e) {
    throw new Exception("Test exception. This should be catched by resharper!!!");
  }

}

2 comments
Comment actions Permalink

Hello,

Why is my exception not caught by 'resharper'' and displayed with
resharper's default exception dialog?


ReSharper ignores any exceptions that do not have ReSharper code in their
stack trace (otherwise we'd get lots of false positives for any foreign managed
code in VS). Any WinForms code calling into your handlers is likely to have
only WinAPI wrappers and your code on the stack traces, and thus would not
pass the filter.

How can I change my code such
that my exceptions are catched by resharper?


Add try-catch, use the Logger class to spawn the dialog for the caught exception
(LogException method in most cases).

And another question is that with resharper 4.5 I could add a 'form'
as a control to an ToolWindowContent. With resharper 5 beta  I get an
exception. Is this by design or will this be fixed ?


What do you mean by a "form"? Is this the System.Windows.Forms.Form class?
If yes, I do not think it should be allowed, at a glance. What's the code
you're using from the base Form class that you need in a tool window?


Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


0
Comment actions Permalink

It's good to know how resharper handles exception, thanks for the good information about the stacktrace.

Sorry, yes I mean 'System.Windows.Forms.Form'. Of course it does not give any benefits, it was just that by accident my test was using this class in 4.5. (which worked fine, but failed in 5.0), and after all Form inherits from Control. But of course in a real plugin I wouldn't use such a class.

Thanks for your help.

Best,

Joe

0

Please sign in to leave a comment.