473,624 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to identify exception ?

Hi all!

Is it possible to identify throw statement, within catch( ... )?
Can I identify type of exception passed to catch(...) ?
I'm trying to identify problem, which is probably somewhere in library
which I'm using.
This is real-time program, so step-by-step debbuging is very diffcult.
Program is written in gcc-3.3 working on Linux

best regards
Jarek.
Sep 13 '05 #1
11 2277
> Hi all!

Is it possible to identify throw statement, within catch( ... )?
Can I identify type of exception passed to catch(...) ?
I'm trying to identify problem, which is probably somewhere in library
which I'm using.
This is real-time program, so step-by-step debbuging is very diffcult.
Program is written in gcc-3.3 working on Linux

best regards
Jarek.


If all you can do to catch the exception is through catch(...) then the only
assumption your handling code should make is that an exception is thrown. If
the exception itself is polymorphic and you know the base type then you can
use RTTI (e.g. dynamic_cast, typeid(), etc)

ben
Sep 13 '05 #2
I'm not recommending this approach but...
If you explictly throw then you can use the __LINE__ and __FILE__
preprocessor directives either to create an object, or if you are
abandoning any sanity set a global variable.
If you do this, then I wany joint credit in the obfuscated C++ contest
:)

Sep 13 '05 #3
benben wrote:
If all you can do to catch the exception is through catch(...) then the only
assumption your handling code should make is that an exception is thrown. If
the exception itself is polymorphic and you know the base type then you can
use RTTI (e.g. dynamic_cast, typeid(), etc)


The problem is that I don't know anything about this exception. I tried
few catch-es (exception, char *, etc), but no one can match.

Is there some tool to analyze to analyze code to find all throws ?
Something like in eclipse for java ?

best regards
Jarek
Sep 13 '05 #4
> The problem is that I don't know anything about this exception. I tried
few catch-es (exception, char *, etc), but no one can match.


So doesn't the library documentation specifies the types to be thrown? also
check exception specification in function declarations.
Sep 13 '05 #5
benben wrote:
The problem is that I don't know anything about this exception. I tried
few catch-es (exception, char *, etc), but no one can match.
So doesn't the library documentation specifies the types to be thrown? also
check exception specification in function declarations.


It is not clear, and code doesn't match manuals.

I'm studying now what Bjarne Stroustrup in his C++ book is thinking
about this :)

Thank you are any sugestions.
best regards
Jarek.
Sep 13 '05 #6
I think, as benben said, your best bet is to use RTTI.

Sep 13 '05 #7
>I think, as benben said, your best bet is to use RTTI.


But RTTI relies on a pointer being thrown. Most systems don't throw pointers
anymore.

That's why it is always a good idea to have an exception hierarchical
exception family...

Ben
Sep 14 '05 #8

benben schreef:
I think, as benben said, your best bet is to use RTTI.


But RTTI relies on a pointer being thrown. Most systems don't throw pointers
anymore.


No it doesn't. RTTI works on pointers and references. You can catch
by reference, so that will allow you to catch non-pointers. That
doesn't
solve an undocumented exeption/catch(...) problem, though.

HTH,
Michiel Salters

Sep 14 '05 #9
> No it doesn't. RTTI works on pointers and references. You can catch
by reference, so that will allow you to catch non-pointers. That
doesn't
solve an undocumented exeption/catch(...) problem, though.

HTH,
Michiel Salters


But you can't have a void& can you. The fact is, dumping the exception
requires assumption on where the exception object is actually stored.

Ben
Sep 15 '05 #10

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

Similar topics

8
487
by: DraguVaso | last post by:
Hi, I want my application do different actions depending on the exception it gets. For exemple: I have an SQL-table with a unique index. In case I try to Insert a record that's alreaddy in it I get this exception: "Cannot insert duplicate key row in object 'tblTelephones' with unique index 'UniqueValues'." What I'm looking for is a way to identify the exception: in case I get this
6
2488
by: Pieter | last post by:
Hi, For some procedures that throws exceptions, I would like to show different messages to the user depending on what type of exception he's getting. For instance this one: when the file is locked, I want a messagebox to tell that the user has to close the file first. Is there a way to identify an exception by some kind of unique number or something like this? I don't want to identify it on the Exception Message because some users are...
0
8234
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
8677
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
8620
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
8335
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
8474
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
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
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.