473,224 Members | 1,581 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,224 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 2769
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...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.