473,659 Members | 2,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2287
JE


On Jan 23, 4:34 pm, "Chris" <cchie...@roche ster.rr.comwrot e:
<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.co mwrote:
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::as sign(). 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::as sign(). 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...@roche ster.rr.comwrot e:
Thanks, JE and Ian. That was fast! :-)

On Jan 23, 8:37 pm, Ian Collins <ian-n...@hotmail.co mwrote:
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::as sign(). 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.u kwrote:
On 24 Jan, 02:02, "Chris" <cchie...@roche ster.rr.comwrot e:
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::s tring 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
4836
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 change. Occasionally, it blows up with an Application Exception. It seems to only die at the customer site
5
72244
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 => Exception: "The requested address is not valid in its context" This works:
5
2694
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 return ::memcmp(_First1, _First2, _Count); On inspecting these variables, the strings are in fact equal when the exception occurs and _Count is the right size. As a test I replaced this code in the system include file with a for loop to do the...
2
1424
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 Exception" Try 'Create the connection and command objects oConn = GetMsAccessOledbConnection(Pathdb, "admin", "")
4
2894
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 e) { Debug.WriteLine("WWWPage.Search_Click()"); ... try
1
3012
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 called; here's the code: protected void Search_Click(object sender, EventArgs e) { Debug.WriteLine("WWWPage.Search_Click()"); ...
0
2658
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 isolated it to the OnSortCommands presence. When I use a code behind it doesn't fire any events on the back end and the global error handler grabs it. I put together a very simple example to illustrate the problem below. If anyone has an idea of...
0
1066
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 little Add button in the Exceptions window doesn't seem to do anything for me. How do you use it? Adding "UnsupportedException" (or fully qualified) and unchecking break on thrown has no effect. Also, changing the "Thrown" column on...
4
3240
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: Solution will NOT compile. Error is simply: "External component has thrown an exception". NO other details.
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8525
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7356
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.