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

Exception Handling Problem

Hi,

Whenever an exception is raised, I ma getting just "Abort" and not the
customized message.

Even the simplest program ,like this is aborting...
#include <iostream.h>

int main () {
char myarray[10];
try
{
for (int n=0; n<=10; n++)
{
if (n>9) throw "Out of range";
myarray[n]='z';
}
}
catch (char * str)
{
cout << "Exception: " << str << endl;
}
return 0;
}

I am running on g++ 3.2.3 on solaris.
I did try to print the values inside loop and it does print till 10 and
then Aborts.

Any idea why this is happening ?

Thanks.

Jul 23 '05 #1
5 1221
Adding more. In the debugger I see
Program received signal SIGABRT, Aborted.
0xff21fc04 in _libc_kill () from /lib/libc.so.1

And why would the program receive the same ?? Any hints ?

Thanks.

Jul 23 '05 #2
I'm not at a machine with a compiler, so I can't verify this, but "Out
of range" is a const char *, which you aren't catching. You need to
change your catch.

-Brian

Jul 23 '05 #3

BigBrian wrote:
I'm not at a machine with a compiler, so I can't verify this, but "Out of range" is a const char *, which you aren't catching. You need to
change your catch.
Yes changing that to const char * worked.
Thanks -Brian


Jul 23 '05 #4
<co*******@gmail.com> wrote in message
BigBrian wrote:

I'm not at a machine with a compiler, so I can't verify this, but

"Out
of range" is a const char *, which you aren't catching. You need to
change your catch.

Yes changing that to const char * worked.


Not sure if it is standard across platforms. I think that in builtin C
strings have type char*, and C++ might inherit this rule for historical
reasons. Making builtin strings have type const char* might be an
extension.

So what I'm saying is that if you compile on other compilers, they might
catch char*, but const char* would go unhandled. On gnu, try compiling
with --pedantic to enforce the ANSI rules, and see what happens. Though to
be sure, you should also compile on other platforms.

Why not throw a std::runtime_error or some class derived from
std::exception?
Jul 23 '05 #5
Siemel Naran wrote:
<co*******@gmail.com> wrote in message
BigBrian wrote:
I'm not at a machine with a compiler, so I can't verify this, but

"Out
of range" is a const char *, which you aren't catching. You need to change your catch.

Yes changing that to const char * worked.


Not sure if it is standard across platforms. I think that in builtin

C strings have type char*, and C++ might inherit this rule for historical reasons. Making builtin strings have type const char* might be an
extension.
In my copy of the standard, 2.13.4.1 states that a string literal has
type array of const char. So, catching a const char * is the correct
way to go on all conforming implementations.
So what I'm saying is that if you compile on other compilers, they might catch char*, but const char* would go unhandled.
This is false as noted above.
On gnu, try compiling with --pedantic to enforce the ANSI rules, and
see what happens. Though to be sure, you should also compile on other
platforms.


<OT>
The GNU C++ compiler option --pedantic is not a panacea for determining
whether or not your code meets the language standard. It only issues
diagnostics for stuff that the standard specifically says it has to,
and IIRC it doesn't do so in every case.
</OT>

[snip good advice about throwing a std::exception]

Kristo

Jul 23 '05 #6

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

Similar topics

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...
6
by: Daniel Wilson | last post by:
I am having exception-handling and stability problems with .NET. I will have a block of managed code inside try...catch and will still get a generic ..NET exception box that will tell me which...
7
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
6
by: Kevin Jackson | last post by:
Let's say we log exceptions to the windows application event log using the Exception Management Application Block. Is there a pattern that can be used so the exception is logged only once and not...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
6
by: Nick Reeves | last post by:
While developing the below code I noticed that exceptions were not working as expected. An exception is thrown inside an XML import DLL and not being caught inside the Main() code fragment,...
4
by: Ele | last post by:
When Exception handling disabled compiler still spits out "C++ exception handler used." Why is that? Why does it ask for "Specify /EHsc"? Thanks! c:\Program Files\Microsoft Visual Studio...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
41
by: Stuart Golodetz | last post by:
Hi all, Just wondering whether there's any reason why exception specifications are enforced at runtime, rather than at compile-time like in Java? (This was prompted by reading an article on...
4
by: DHS1 | last post by:
Hey guys. I have a lab that is due in two weeks, but I wanted to start on it now. Problem is, I'm at home during christmas break so I can't ask my professors. Here's my problem: I am given a very...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.