How to find the line number an exception happens at?

I’m receiving a very non-descriptive error in a BPM. The only thing I can gather is that it is of type “System.Exception” - the stack trace is useless (as usual).

I tried to figure out exactly where it was in my code (line number wise) by wrapping my entire BPM in a try/catch:

try {
   // all my code here
} catch (Exception e) {
    var st = new StackTrace(e, true);
    var frame = st.GetFrame(st.FrameCount-1);
    var line = frame.GetFileLineNumber();
    PublishInfoMessage($"Line number {line}", XX, YY, "", "");
}

I have added a “using System.Diagnostics” and it passes the syntax check and compiles okay.

But when it runs it always says the line number is 0! I have read that in order for this to work, there must be a “PDB” file but since everything is automatically generated I have no idea how to make that happen.

I’m open to any other method to tell me exactly where the code is failing.

You can add your own tracing into server logs to write it as it’s doing it. The way you have it written I think it’s going to back out all of the variables that it sets once the try fails.

1 Like