digitalmars.D - Line number of Exception instantiation
- bearophile (11/11) Mar 04 2010 What do you think of the idea of the Exception to remember (so later it ...
- Nick Sabalausky (3/18) Mar 04 2010 Doesn't tango's exception tracing do that?
- Fawzi Mohamed (14/36) Mar 04 2010 sure it does, just import TraceExceptions...
- Ellery Newcomer (6/14) Mar 04 2010 Can you actually get line number information with the stack trace? With
- Fawzi Mohamed (15/32) Mar 05 2010 the answer is "it depends", first you have to compile with -g, then
- BCS (5/9) Mar 04 2010 It shouldn't be hard, add default parameters to the constructor:
- Fawzi Mohamed (3/13) Mar 04 2010 yes I always do it, I find it useful information, and it is available
- Robert Jacques (3/19) Mar 04 2010 You mean, like enforce(false, "message")?
What do you think of the idea of the Exception to remember (so later it can be shown if uncaught) the line number and file name where it was instantiated? void foo() { auto e = new Exception(""); // instantiation line number here throw e; } void main() { foo(); } Exceptions get caught, rethrown, stored, etc. But in many cases in my code they are instantiated close to where the cause was. So knowing such line number can be useful (if you are using a debugger this is not so useful). Bye, bearophile
Mar 04 2010
"bearophile" <bearophileHUGS lycos.com> wrote in message news:hmovte$2431$1 digitalmars.com...What do you think of the idea of the Exception to remember (so later it can be shown if uncaught) the line number and file name where it was instantiated? void foo() { auto e = new Exception(""); // instantiation line number here throw e; } void main() { foo(); } Exceptions get caught, rethrown, stored, etc. But in many cases in my code they are instantiated close to where the cause was. So knowing such line number can be useful (if you are using a debugger this is not so useful). Bye, bearophileDoesn't tango's exception tracing do that?
Mar 04 2010
On 2010-03-04 21:29:15 +0100, "Nick Sabalausky" <a a.a> said:"bearophile" <bearophileHUGS lycos.com> wrote in message news:hmovte$2431$1 digitalmars.com...sure it does, just import TraceExceptions... The exception will contain the stacktrace at the throwing point (adresses)... and with printOut you can get a symbolic trace (if possible). I have also tried to have a way to get the trace of all threads http://github.com/fawzi/blip/blob/master/blip/util/TraceAll.d it is not perfect, probably I should trade a little bit more of memory and suspend all threads (instead of one at a time), but it can be useful when there is a deadlock and you want to see who is the culprit. that uses signals, so it is unsafe, also it will deadlock if the gc tries to suspend all threads while tracing, but I find it useful all the same, so that you don't have to attach a debugger... FawziWhat do you think of the idea of the Exception to remember (so later it can be shown if uncaught) the line number and file name where it was instantiated? void foo() { auto e = new Exception(""); // instantiation line number here throw e; } void main() { foo(); } Exceptions get caught, rethrown, stored, etc. But in many cases in my code they are instantiated close to where the cause was. So knowing such line number can be useful (if you are using a debugger this is not so useful). Bye, bearophileDoesn't tango's exception tracing do that?
Mar 04 2010
On 03/04/2010 02:49 PM, Fawzi Mohamed wrote:Can you actually get line number information with the stack trace? With my setup, it looks like line numbers should be in there, but they never get initialized. p.s. TraceExceptions is awesome; I can't believe I never knew about them until a week or two agosure it does, just import TraceExceptions... The exception will contain the stacktrace at the throwing point (adresses)... and with printOut you can get a symbolic trace (if possible).Bye, bearophileDoesn't tango's exception tracing do that?
Mar 04 2010
On 2010-03-05 02:05:19 +0100, Ellery Newcomer <ellery-newcomer utulsa.edu> said:On 03/04/2010 02:49 PM, Fawzi Mohamed wrote:the answer is "it depends", first you have to compile with -g, then windows works (thanks to h3r3tic impl), linux has recently been added by wm4 (after release if I remember correctly), with mac you are out of luck. please not that a solution using addr2line as BCS did should also work on linux, it was not done because being able to give a partial info even if the program was crashing was considered more important. Still you can call addr2line yourself after the fact to get the line information (if available), I had asked for someone to write a stacktrace parser that would complete the stacktrace, or writing a addr2line backend, but nobody stepped up, and now wm4 solution seem to work well.Can you actually get line number information with the stack trace? With my setup, it looks like line numbers should be in there, but they never get initialized.sure it does, just import TraceExceptions... The exception will contain the stacktrace at the throwing point (adresses)... and with printOut you can get a symbolic trace (if possible).Bye, bearophileDoesn't tango's exception tracing do that?p.s. TraceExceptions is awesome; I can't believe I never knew about them until a week or two agohappy to hear that :)
Mar 05 2010
Hello bearophile,What do you think of the idea of the Exception to remember (so later it can be shown if uncaught) the line number and file name where it was instantiated?It shouldn't be hard, add default parameters to the constructor: this(string msg, string file = __FILE__, int line = __LINE__) { ... } -- ... <IXOYE><
Mar 04 2010
On 2010-03-04 21:38:09 +0100, BCS <none anon.com> said:Hello bearophile,yes I always do it, I find it useful information, and it is available even in a fully optimized build...What do you think of the idea of the Exception to remember (so later it can be shown if uncaught) the line number and file name where it was instantiated?It shouldn't be hard, add default parameters to the constructor: this(string msg, string file = __FILE__, int line = __LINE__) { ... }
Mar 04 2010
On Thu, 04 Mar 2010 13:58:54 -0500, bearophile <bearophileHUGS lycos.com> wrote:What do you think of the idea of the Exception to remember (so later it can be shown if uncaught) the line number and file name where it was instantiated? void foo() { auto e = new Exception(""); // instantiation line number here throw e; } void main() { foo(); } Exceptions get caught, rethrown, stored, etc. But in many cases in my code they are instantiated close to where the cause was. So knowing such line number can be useful (if you are using a debugger this is not so useful). Bye, bearophileYou mean, like enforce(false, "message")?
Mar 04 2010