private static SentryStacktrace ParseExceptionStackTrace(Exception exception) { var t = new SentryStacktrace(); StackTrace trace = new StackTrace(exception, true); for (int i = 0; i < trace.FrameCount; i++) { var frame = trace.GetFrame(i); int lineNo = frame.GetFileLineNumber(); if (lineNo == 0) { //The pdb files aren't currently available lineNo = frame.GetILOffset(); } var method = frame.GetMethod(); var frameData = new ExceptionFrame() { Filename = frame.GetFileName(), //Module = (method.DeclaringType != null) ? method.DeclaringType.FullName : null, Function = method.Name, //Source = method.ToString(), LineNumber = lineNo, }; t.Frames.Add(frameData); } return(t); }
private static SentryStacktrace ParseUnityStackTrace(string unityTrace) { /* * Example Unity Trace String: * * ExceptionGenerator.ThrowNestedB () (at Assets/Script/ExceptionGenerator.cs:26) * ExceptionGenerator.ThrowNestedA () (at Assets/Script/ExceptionGenerator.cs:22) * ExceptionGenerator.Update () (at Assets/Script/ExceptionGenerator.cs:13) */ var t = new SentryStacktrace(); var lines = unityTrace.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { var parts = lines[i].Split(new[] { "(", ")", ":" }, StringSplitOptions.RemoveEmptyEntries); var frame = new ExceptionFrame(); frame.Function = parts[0]; frame.Filename = parts[2].Remove(0, 3); frame.LineNumber = Int32.Parse(parts[3]); t.Frames.Add(frame); } return(t); }
private static SentryStacktrace ParseUnityStackTrace(string unityTrace) { /* * Example Unity Trace String: * * ExceptionGenerator.ThrowNestedB () (at Assets/Script/ExceptionGenerator.cs:26) * ExceptionGenerator.ThrowNestedA () (at Assets/Script/ExceptionGenerator.cs:22) * ExceptionGenerator.Update () (at Assets/Script/ExceptionGenerator.cs:13) * RamjetAnvil.StateMachine.StateMachine`1[StartupScreen].Transition (StateId stateId, System.Object[] args) */ var t = new SentryStacktrace(); var lines = unityTrace.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = lines.Length - 1; i >= 0; i--) { var parts = lines[i].Split(new[] { " (at ", ".cs:" }, StringSplitOptions.RemoveEmptyEntries); var frame = new ExceptionFrame(); if (parts.Length == 3) { frame.Function = parts[0]; frame.Filename = parts[1] + ".cs"; frame.LineNumber = Int32.Parse(parts[2].Replace(")", "")); t.Frames.Add(frame); } else { frame.Function = lines[i]; frame.Filename = "unknown"; frame.LineNumber = -1; } } return(t); }
/// <summary> /// Initializes a new instance of the <see cref="SentryStacktrace"/> class. /// </summary> /// <param name="exception">The <see cref="Exception"/>.</param> public SentryStacktrace(Exception exception) { if (exception == null) { return; } StackTrace trace = new StackTrace(exception, true); var frames = trace.GetFrames(); if (frames == null) { return; } int length = frames.Length; Frames = new ExceptionFrame[length]; for (int i = 0; i < length; i++) { StackFrame frame = trace.GetFrame(i); Frames[i] = new ExceptionFrame(frame); } }
public void Constructor_NullFrameMethod_DoesNotThrow() { // on some platforms (e.g. on mono), StackFrame.GetMethod() may return null // e.g. for this stack frame: // at (wrapper dynamic-method) System.Object:lambda_method (System.Runtime.CompilerServices.Closure,object,object)) var stackFrame = new StackFrameWithNullMethod(); var frame = new ExceptionFrame(stackFrame); Assert.AreEqual("(unknown)", frame.Module); Assert.AreEqual("(unknown)", frame.Function); Assert.AreEqual("(unknown)", frame.Source); }
/// <summary> /// Initializes a new instance of the <see cref="SentryStacktrace"/> class. /// </summary> /// <param name="e">The decimal.</param> public SentryStacktrace(Exception e) { StackTrace trace = new StackTrace(e, true); if (trace.GetFrames() != null) { int length = trace.GetFrames().Length; Frames = new ExceptionFrame[length]; for (int i = 0; i < length; i++) { StackFrame frame = trace.GetFrame(length - i - 1); Frames[i] = BuildExceptionFrame(frame); } } }
private static ExceptionFrame ParseExceptionFrame(string line) { var match = FramePattern.Match(line); if (!match.Success) return null; var frame = new ExceptionFrame(null); frame.Function = match.Groups[1].Value; if (match.Groups[2].Success) frame.AbsolutePath = match.Groups[2].Value; if (match.Groups[3].Success) frame.LineNumber = Int32.Parse(match.Groups[3].Value); return frame; }
/// <summary> /// Initializes a new instance of the <see cref="SentryStacktrace"/> class. /// </summary> /// <param name="exception">The <see cref="Exception"/>.</param> public SentryStacktrace(Exception exception) { if (exception == null) return; StackTrace trace = exception is CustomStackTraceException ? ((CustomStackTraceException)exception).StackTraceObject : new StackTrace(exception, true); var frames = trace.GetFrames(); if (frames == null) return; int length = frames.Length; Frames = new ExceptionFrame[length]; for (int i = 0; i < length; i++) { StackFrame frame = trace.GetFrame(i); Frames[i] = new ExceptionFrame(frame); } }