Board index » delphi » Re: Error Handling: Which line caused the error?

Re: Error Handling: Which line caused the error?


2006-11-14 02:49:16 AM
delphi143
SamFelis writes:
Quote
I try and use try..except handling in all my methods (along w/ unit
and method names) and it helps figure out which method the error is
housed in. However, this really doesn't tell me WHICH line the error
is on.

Is there a way to figure out which line contained the error.
It's very likely that the try/except in all of your methods is
breaking the feature which shows you precisely what you're trying to
find out. The feature you need is the call stack. I wrote a primer here:
blogs.teamb.com/craigstuntz/articles/UsingTheCallStack.aspx
Peppering your code with try/excepts which swallow exceptions will
make this much less useful.
--
Craig Stuntz [TeamB] ?Vertex Systems Corp. ?Columbus, OH
Delphi/InterBase Weblog : blogs.teamb.com/craigstuntz
All the great TeamB service you've come to expect plus (New!)
Irish Tin Whistle tips: learningtowhistle.blogspot.com
 
 

Re: Error Handling: Which line caused the error?

"Craig Stuntz [TeamB]" <XXXX@XXXXX.COM [a.k.a. acm.org]>wrote
in news:XXXX@XXXXX.COM:
Quote
It's very likely that the try/except in all of your methods is
breaking the feature which shows you precisely what you're trying to
find out. The feature you need is the call stack. I wrote a primer here:

blogs.teamb.com/craigstuntz/articles/UsingTheCallStack.aspx
Thanks for the link. I found some call stack information elsewhere, but
haven't been able to completely digest it as of yet.
 

Re: Error Handling: Which line caused the error?

"Mike Williams (TeamB)" <mlwi!!iams@gmail!.com>wrote in
Quote
When running in the IDE the de{*word*81} should be stopping on the line
containing the exception. You don't even need try/except block for
this. Under de{*word*81} options, make sure you have "Stop on Delphi
Exceptions" checked.

And sometimes the solution is often the simplest. I had forgotten about
this feature. Thanks for the reminder.
 

Re: Error Handling: Which line caused the error?

SamFelis writes:
Quote
I try and use try..except handling in all my methods (along w/ unit
and method names) and it helps figure out which method the error is
housed in. However, this really doesn't tell me WHICH line the error
is on.
When running in the IDE the de{*word*81} should be stopping on the line
containing the exception. You don't even need try/except block for
this. Under de{*word*81} options, make sure you have "Stop on Delphi
Exceptions" checked.
--
-Mike (TeamB)
 

Re: Error Handling: Which line caused the error?

SamFelis writes:
Quote
I try and use try..except handling in all my methods (along w/ unit and
method names) and it helps figure out which method the error is housed in.
However, this really doesn't tell me *WHICH* line the error is on.

Is there a way to figure out which line contained the error. I could step
through it line-by-line, but on some of my methods there's either too many
lines or it doesn't always fail.

Any suggestions?
Hi there!
try except is excellent way to debug your app, if u know how to use it.
Try Except block isn't just try except, its a class witch is created on
exception.
so lets try divide with zero
....
i:= 100 / 0; //exception goes here
...
lets put exception block
try
i:= 100/0;
except
showmessage('Can't divide with zero!');
end;
but as u know there can be much more reasons why operation can not be
done.
so lets tune up exception block.
try
i:= 100/0
except
on e:exception do
begin
showmessage(e.message);
end;
end;
now you will get message why part of your code went into exception
block.
regards.