|
Posted by Oli Filth on 10/10/05 17:35
Seamus M wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:ov-dnYfolKwGStTeRVn-oA@comcast.com...
> > Seamus M wrote:
> >> It seems when I use the getLine() method of the Exception class, it
> >> returns the line number of the "throw new Exception" statement and not
> >> the line number where the error actually occured in the source file. Am
> >> I doing something wrong?
> >>
> >
> > How is the exception supposed to know where the error occurred? It could
> > have been anything - bad return code, incorrect data, whatever. But in all
> > cases, it's something you had to detect. This might have been many lines
> > of code before you actually threw the exception, or even in a different
> > (included) file.
> >
> > All the exception can tell is where you threw it.
> >
>
> It appears the exception should be thrown on the line immediately after the
> potenially error causing code for "getLine()" to be any use. I was
> anticipating it to work like the built-in errors which tell you what line of
> code caused the error.
>
I imagine you're using exceptions something like:
....
if (Some Bad Condition)
{
throw new Exception("You fool!");
}
....
As Jerry said, the exception itself has no idea what caused the error,
and what line that corresponds to.
But getLine() will direct you to the throw... line, which should be
enough of a clue to work out where the error was!
--
Oli
Navigation:
[Reply to this message]
|