I want to get the name of an exception function inferred from a dll in asp.net.
You can use stack trace
Exception.StackTrace Property
Class stacktrace
Represents a stack trace, which is an ordered collection of one or more stack frames.
Class stackframe
A StackFrame call stack is created and pushed for each function call executed during the execution of the thread. The stack frame always includes Information about the database method and, optionally, includes the file name, line number, and column number.StackFrame Debug . Debug , . , , , StackFrame.
A StackFrame call stack is created and pushed for each function call executed during the execution of the thread. The stack frame always includes Information about the database method and, optionally, includes the file name, line number, and column number.
StackFrame Debug . Debug , . , , , StackFrame.
StackTrace .
:
public void Throw() { throw new MyException(); } public void CallThrow() { Throw(); } [Test] public void GetThrowingMethodName() { try { CallThrow(); Assert.Fail("Should have thrown"); } catch (MyException e) { MethodBase deepestMethod = new StackTrace(e).GetFrame(0).GetMethod(); string deepestMethodName = deepestMethod.Name; Assert.That(deepestMethodName, Is.EqualTo("Throw")); } }
stacktrace system.diagnostic - linqpad, .
void Main() { try { test(); } catch(Exception ex) { StackTrace st = new StackTrace(); st.GetFrame(1).GetMethod().Name.Dump(); } } // Define other methods and classes here public void test() { throw new NotImplementedException(); }
StackTrace.GetFrame
Source: https://habr.com/ru/post/1739825/More articles:Странное использование индекса в Mysql - sqlPrintable DataTable Google Visualizations - javascriptto load Javascript object from file - jqueryUse ribbon interface in open source applications - c ++Methods in super that will be subclassed anyway (Cocoa) - superA pdf download option should appear - javascriptwe can add system icons to flex application - flexecho problem in audio / video chat application - echoSingle Regex to filter Roman numerals from text files - regexкак изменить '(1,2,3,4)' до '1,2,3,4' - javascriptAll Articles