473,383 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Exception Class Question -> getLine()

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
4 2778
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: RT Lange | last post by:
>>> class E1(Exception): pass >>> class E2(E1): pass >>> i = E2('foo') >>> raise E1(i) Traceback (most recent call last): File "<pyshell#5>", line 1, in ? raise E1(i) E1: foo
6
by: Páll Ólafsson | last post by:
Hi I have a problem with the Microsoft.ApplicationBlocks.ExceptionManagement? I can't get it to work in RELEASE mode? If I run the project in debug mode the block works fine but when I run the...
11
by: Dave | last post by:
try { ... } catch (exception e) { cout << e.what() << endl; } In the code above, e is caught by value rather than polymorphically (assume
3
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? ...
0
by: guy | last post by:
i have a method which throws an exception. the thing i dont understand is that the only change between the two versions is a line of code AFTER the one that throws the exception - see code below...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
2
by: | last post by:
I would appreciate some help in understanding the simple C# example relating to handling exceptions. This one relates to catching an error thrown by dividing number by zero. There are a few...
6
by: Vadivel Kumar | last post by:
I've a problem in handling a custom exception The following is my custom exception class: public class AppException : public Exception { public AppException (string message, Exception...
3
by: Jarod_24 | last post by:
Throw new Excption ("bla, bla, bla") .... Catch E as Exception If E.Message.Equals("bla, bla, bla") Then ... Mostly i just use the standard "Exception"-object whenever i throw an exception,...
1
by: metsys | last post by:
We have an ASP.NET 2.0 (C#) application that is divided into multiple layers. The multiple layers come from having a web project and 2 different class library projects in the same solution. I'm...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.