By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

Exception Class Question -> getLine()

P: n/a
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?

- Seamus
Oct 10 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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?

- Seamus


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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 10 '05 #2

P: n/a
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.

Thanks for your input.

- Seamus

"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:ov********************@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?

- Seamus


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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 10 '05 #3

P: n/a
Seamus M wrote:
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.

Thanks for your input.

- Seamus

"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:ov********************@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?

- Seamus


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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================



There's a difference here. The built-in errors know where the error
occurred, because they detected the error.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 10 '05 #4

P: n/a
Seamus M wrote:
"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:ov********************@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

Oct 10 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.