For example, in one place...
//---------------a try { // some network call } catch(WebException we) { throw new MyCustomException("some message ....", we); }
...and in another place...
//--------------b try { // invoke code above } catch(MyCustomException we) { Debug.Writeline(we.stacktrace); // <---------------- }
The stacktrace I print, it only start from a to b, it doesnt include the inner stacktrace from the WebException.
How can I print all the stacktrace???
By default, the stack trace is captured immediately before an exception object is thrown. Use StackTrace to get stack trace information when no exception is being thrown.
The printStackTrace() method of Java. lang. Throwable class used to print this Throwable along with other details like class name and line number where the exception occurred means its backtrace. This method prints a stack trace for this Throwable object on the standard error output stream.
To print a stack trace to log you Should declare logger and method info(e. toString()) or log(Level.INFO, e. toString()). Logging is the process of writing log messages during the execution of a program to get error and warning messages as well as info messages.
I usually use the .ToString()
method on exceptions to present the full exception information (including the inner stack trace) in text:
catch (MyCustomException ex) { Debug.WriteLine(ex.ToString()); }
Sample output:
ConsoleApplication1.MyCustomException: some message .... ---> System.Exception: Oh noes! at ConsoleApplication1.SomeObject.OtherMethod() in C:\ConsoleApplication1\SomeObject.cs:line 24 at ConsoleApplication1.SomeObject..ctor() in C:\ConsoleApplication1\SomeObject.cs:line 14 --- End of inner exception stack trace --- at ConsoleApplication1.SomeObject..ctor() in C:\ConsoleApplication1\SomeObject.cs:line 18 at ConsoleApplication1.Program.DoSomething() in C:\ConsoleApplication1\Program.cs:line 23 at ConsoleApplication1.Program.Main(String[] args) in C:\ConsoleApplication1\Program.cs:line 13
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With