/// <summary>Adds the exception.</summary> /// <param name="offset">The offset of this method.</param> /// <param name="exception">The exception.</param> /// <param name="thrownHere">if set to <c>true</c> if the exception was thrown by this method.</param> public void AddException(int offset, ThrownException exception, bool thrownHere) { if (!typeof(Exception).IsAssignableFrom(exception.Exception)) { } bool got = this.UnhandledExceptions.Contains(exception); if (got && !thrownHere) { return; } if (this.MethodBody != null) { // see if any exception handler covers this instruction foreach (ExceptionHandlingClause handler in this.ExceptionHandlersAtOffset(offset)) { // is it for this exception? if (handler.CatchType.IsAssignableFrom(exception.Exception)) { return; } } } // not handled; add it to the list(s) if (!got) { this.UnhandledExceptions.Add(exception); } if (thrownHere) { this.ThrownExceptions.Add(exception); } }
public MethodItem(Method method, ThrownException exception) { this.Method = method; this.Exception = exception; }
public MethodEventArgs(Method method, Method callingMethod, ThrownException exception) { this.Method = method; this.CallingMethod = callingMethod; this.Exception = exception; }
private List<ListViewItem> GetCallstackItems(ItemInfo info, ThrownException ex) { List<ListViewItem> items = new List<ListViewItem>(); //MethodContainer.CallStack stack = this.MethodContainer.Analysis.GetCallstack(ex.Method); CallStack stack = ((MethodItem)info.Data).Method.Analysis.GetCallstack(ex.Method); // add the methods in it if (stack != null) { bool first = true; ItemInfo previous = null; foreach (Method m in stack) { if (first) { first = false; continue; } ItemInfo child = MakeItem(null, m); if (previous != null) { ((MethodItem)child.Data).CalledBy = ((MethodItem)previous.Data).Method; } else { ((MethodItem)child.Data).CalledBy = ((MethodItem)info.Data).Method; } child.Item.IndentCount = info.Item.IndentCount + 1; child.Parent = info; child.PreviousChild = previous; previous = child; items.Add(child.Item); } // add an item for the throw statement ItemInfo throwItem = MakeItem(ex); throwItem.Item.Text = "throw " + ex.Exception.Name; throwItem.Item.IndentCount++; throwItem.PreviousChild = previous; throwItem.Parent = info; items.Add(throwItem.Item); } return items; }
/// <summary> /// Makes a new item. /// </summary> /// <param name="exception">The exception.</param> /// <param name="method">The method.</param> /// <param name="group">The group.</param> /// <returns></returns> protected ItemInfo MakeItem(ThrownException exception, Method method = null, ListViewGroup group = null) { bool isMethod = (method != null); bool isProperty = isMethod && method.MethodBase.IsProperty(); bool isThrow = !isMethod && (exception != null); if (!isMethod) { method = exception.Method; } ListViewItem item; PropertyInfo pi = null; if (isProperty) { bool getter = method.MethodBase.Name.StartsWith("get_"); pi = method.MethodBase.GetMethodProperty(); item = new ListViewItem(string.Format(CultureInfo.InvariantCulture, "{0} ({1})", pi.Name, getter ? "get" : "set")); } else { item = new ListViewItem(method.ToString()); } if (isProperty) { item.ImageKey = NodeInfo.ImageKeyFromObject(pi); } else if (isMethod) { // use the method for the icon item.ImageKey = NodeInfo.ImageKeyFromObject(method.MethodBase); } else { // use the exception for the icon item.ImageKey = NodeInfo.ImageKeyFromObject(exception.Exception); } ItemInfo info; MethodItem me = new MethodItem(method, exception); if (exception == null) { info = new ItemInfo(item, me, NodeType.Method); item.SubItems.Add(""); } else { info = new ItemInfo(item, me, NodeType.Method); info.Expandable = !isThrow; item.SubItems.Add(exception.Exception.Name); } item.Tag = info; item.SubItems.Add(method.MethodBase.DeclaringType.Name); item.SubItems.Add(method.MethodBase.DeclaringType.Module.Name); item.IndentCount = 1; if (group != null) { item.Group = group; } return info; }