473,405 Members | 2,421 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,405 software developers and data experts.

Thrown exception doesn't get caught where it "should."

Hello all...

I have a program with the following structure (all classes
mentioned are of my own creation, and none of the classes contain try
or catch blocks):

- main() consists of a large try block with several catch blocks I
will describe below. main(), within the try block, declares, and
implicitly default-constructs, a variable (object) of class AppDBConn.

- The default AppDBConn constructor uses initialization syntax to
invoke a one-argument (std::string) constructor of its base class
IniDBConn.

- The one-argument IniDBConn constructor uses 'new' to construct an
IniFile object, again passing one argument (std::string). (IniFile
derives separately from IniCheck.)

- There is a hierarchy of exception classes: IniError derives from
RunError, which derives from Error, which is a base class.

My problem is this: main() has catch blocks for IecIniError and
"..." (catch-all). The IniFile constructor encounters an error and
invokes a base-class (IniCheck) method to process it, which culminates
with the throwing of an IniError. None of main()'s catch blocks --
including the catch-all block -- catch this, and the program SEGVs
instead of terminating gracefully.

By way of troubleshooting, If I eliminate main()'s use of
AppDBConn, and instead construct an IniDBConn object directly, the
problem remains; the thrown exception is not caught.

If I eliminate main()'s use of AppDBConn -and- IniDBConn, and
construct an IniFile object directly, the problem disappears; the
thrown exception IS caught, in main()'s catch block for IniError.

I need to fix this misbehavior, but am at a loss to do so. My
questions are:

1) Are there any coding (mis)constructs that cause this?

2) Could it be a problem with the OS (SuSE Linux 9) and/or compiler
(g++ 3.3.3)?

3) What else might I be overlooking?

I would be grateful for any light anyone could shed.

Thanks in advance,

Chris

Jan 24 '07 #1
7 2271
JE


On Jan 23, 4:34 pm, "Chris" <cchie...@rochester.rr.comwrote:
<snip>
If I eliminate main()'s use of AppDBConn -and- IniDBConn, and
construct an IniFile object directly, the problem disappears; the
thrown exception IS caught, in main()'s catch block for IniError.
<snip>

Perhaps you have another exception while the first exception is
unwinding?

Jan 24 '07 #2
Chris wrote:
Hello all...
>
My problem is this: main() has catch blocks for IecIniError and
"..." (catch-all). The IniFile constructor encounters an error and
invokes a base-class (IniCheck) method to process it, which culminates
with the throwing of an IniError. None of main()'s catch blocks --
including the catch-all block -- catch this, and the program SEGVs
instead of terminating gracefully.
At a guess, it his hitting a coding bug in your exception, if an
exception is thrown and not caught, the program will abort, not crash.

Use your debugger to catch the segv.

--
Ian Collins.
Jan 24 '07 #3
Thanks, JE and Ian. That was fast! :-)

On Jan 23, 8:37 pm, Ian Collins <ian-n...@hotmail.comwrote:
Chris wrote:
...
with the throwing of an IniError. None of main()'s catch blocks --
including the catch-all block -- catch this, and the program SEGVs
instead of terminating gracefully.
At a guess, it his hitting a coding bug in your exception, if an
exception is thrown and not caught, the program will abort, not crash.
Hm. I've been scouring the code for two days now, looking for coding
bugs, without finding any. I don't suppose that this particular
behavior would point to any specific kind of bug? Would the error be
in the exception-class code, or in one of the classes whose removal
from the chain eliminates the problem?
Use your debugger to catch the segv.
Catch as in C++ 'catch' statement, or are you speaking generally? I've
been looking at the code with the debugger and everything is normal
right up until the throw statement SEGVs. The location of the SEGV as
reported by the debugger is std::string::assign(). Prior to this I had
a SEGV on a statement

m_lastStatus = "";

where m_lastStatus is an std::string. Offhand it looks like there's
some sort of weirdness attached to std::string, but I still can't
figure out WHAT.

I guess I'll keep looking!

Chris

Jan 24 '07 #4
Chris wrote:
>>At a guess, it his hitting a coding bug in your exception, if an
exception is thrown and not caught, the program will abort, not crash.


Hm. I've been scouring the code for two days now, looking for coding
bugs, without finding any. I don't suppose that this particular
behavior would point to any specific kind of bug? Would the error be
in the exception-class code, or in one of the classes whose removal
from the chain eliminates the problem?

>>Use your debugger to catch the segv.


Catch as in C++ 'catch' statement, or are you speaking generally? I've
been looking at the code with the debugger and everything is normal
right up until the throw statement SEGVs. The location of the SEGV as
reported by the debugger is std::string::assign(). Prior to this I had
a SEGV on a statement

m_lastStatus = "";
I can only guess, but that would be memory corruption screwing up the
std::string object.

--
Ian Collins.
Jan 24 '07 #5


On 24 Jan, 02:02, "Chris" <cchie...@rochester.rr.comwrote:
Thanks, JE and Ian. That was fast! :-)

On Jan 23, 8:37 pm, Ian Collins <ian-n...@hotmail.comwrote:
Chris wrote:
...
with the throwing of an IniError. None of main()'s catch blocks --
including the catch-all block -- catch this, and the program SEGVs
instead of terminating gracefully.
At a guess, it his hitting a coding bug in your exception, if an
exception is thrown and not caught, the program will abort, not crash.Hm. I've been scouring the code for two days now, looking for coding
bugs, without finding any. I don't suppose that this particular
behavior would point to any specific kind of bug? Would the error be
in the exception-class code, or in one of the classes whose removal
from the chain eliminates the problem?
Use your debugger to catch the segv.Catch as in C++ 'catch' statement, or are you speaking generally? I've
been looking at the code with the debugger and everything is normal
right up until the throw statement SEGVs. The location of the SEGV as
reported by the debugger is std::string::assign(). Prior to this I had
a SEGV on a statement

m_lastStatus = "";

where m_lastStatus is an std::string. Offhand it looks like there's
some sort of weirdness attached to std::string, but I still can't
figure out WHAT.
A wild guess...

You could try changing to:

m_lastStatus = std::string("");

I had some sort of issue with this in VC7.1 and above is IIRC is how I
solved it

HTH

regards
Andy Little

Jan 24 '07 #6
kwikius wrote:
>
You could try changing to:

m_lastStatus = std::string("");

I had some sort of issue with this in VC7.1 and above is IIRC is how I
solved it
Never heard of any such problem in any version of VC++.

However, there is one thing to worry about. None of the std::string
functions that take char*'s guard against being passed something
other than a pointer to the beginning of a null terminated string.
Especially, passing a null pointer is right out!
Jan 24 '07 #7


On Jan 24, 2:48 am, "kwikius" <a...@servocomm.freeserve.co.ukwrote:
On 24 Jan, 02:02, "Chris" <cchie...@rochester.rr.comwrote:
a SEGV on a statement
m_lastStatus = "";
where m_lastStatus is an std::string.

You could try changing to:

m_lastStatus = std::string("");
Thanks, Andy. Unfortunately, this was the very first thing I tried --
which I guess I should have mentioned in the first place -- and it
didn't fix the problem.

However, I do seem to have "solved" the problem, by which I mean that I
set about simplifying the code so as to "distill it down to the
smallest code that demonstrates the problem," as the saying goes -- and
somewhere along the line the problem disappeared.

Specifically, recall that I originally said that
>> - The one-argument IniDBConn constructor uses 'new' to construct an
IniFile object, again passing one argument (std::string).
In that constructor, _before_ the 'new IniFile( string )' construction,
I had a couple of string assignments to member variables:

m_where = "IniDBConn constructor";
m_what = "One-argument construction";

(probably not those exact literals). I took these out.

I then also removed the three-argument IniError constructor --

IniError(std::string msg, std::string where, std::string what) :
RunError (where + ", " + what + ": " + msg) { }

When I rebuilt, the problem was gone.

When I took these statements out and rebuilt my program, the problem
was gone; the thrown IniError was correctly caught in main().

The only construction that seems a little dodgy to me is the string
concatenation in the constructor hand-off between IniError and
RunError. Is that a known no-no?

Thanks, everyone, for all your help.

Chris

Jan 25 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: gregory_may | last post by:
I have an application I created called "JpegViewer.exe". It simply loads a Jpeg file and displays in on the screen. It works great, in my lab. When I am using it at a customer site, things...
5
by: Horst Walter | last post by:
What is wrong here? IPAddress ipAddress = IPAddress.Parse("10.10.20.1"); IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, this.port); this.tcpClient = new TcpClient(ipEndPoint); // PROBLEM HERE...
5
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is ...
2
by: momo | last post by:
I need someone to please explain what the "TRY" does and how it work. How do I know if it is working or not. I have this in my code and I don't know what it does, especially this "Catch ex As...
4
by: R.A.M. | last post by:
Hello, Could you help me plase? I have an ASP.NET page with "Search" button; when button is clicked Search_Click is called; here's the code: protected void Search_Click(object sender, EventArgs...
1
by: R.A.M. | last post by:
Hello, Could you help me plase? I am describing my problem second time because I haven't got a solution. I have an ASP.NET page with "Search" button; when button is clicked Search_Click is...
0
by: JT | last post by:
This seems like it could be an asp.net bug. I am getting the following exception when I add OnSortCommand attribute to a datagrid. I have deleted the temp directories, rebooted etc and I have...
0
by: not_a_commie | last post by:
I would like the (VS2005) debugger to not break when Microsoft.DirectX.DirectInput.UnsupportedException is thrown, which inherits from System.ApplicationException. Is there anyway to do this? The...
4
by: =?Utf-8?B?U0g=?= | last post by:
There seems to be an issue with .NET 3.5/Visual Studio 2008 (Team System). After convincing my company to create our latest project in .NET 3.5, this is kind of reflecting bad on me. Problem:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.