473,388 Members | 1,177 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,388 software developers and data experts.

Getting info about an unknown exception

Is it possible to get some info about an unknown exception,
ie. the "catch (...)" case below:

catch (const blah1 &ex)
{
cout << "blah1 exception." << endl;
}

catch (const blah2 &ex)
{
cout << "blah2 exception." << endl;
}

catch (...)
{
cout << "unknown exception." << endl;
}

Can one get for example the line number where the
unknown exception was thrown?

Oct 12 '08 #1
9 8576
Adem wrote:
Is it possible to get some info about an unknown exception,
ie. the "catch (...)" case below:

catch (const blah1 &ex)
{
cout << "blah1 exception." << endl;
}

catch (const blah2 &ex)
{
cout << "blah2 exception." << endl;
}

catch (...)
{
cout << "unknown exception." << endl;
}

Can one get for example the line number where the
unknown exception was thrown?
No.

a) All information used at the point of the catch has to be stored in the
thrown object (simply because that is the only one not subject to stack
unwinding). And, for all you know, what is caught in the (...) catch clause
could be a char.

b) If you find yourself wishing for that option, chances are that your
design needs fixing. What is the underlying problem you are trying to
solve?
Best

Kai-Uwe Bux
Oct 12 '08 #2
"Kai-Uwe Bux" <jk********@gmx.netwrote:
Adem wrote:
Is it possible to get some info about an unknown exception,
ie. the "catch (...)" case below:

catch (const blah1 &ex)
{
cout << "blah1 exception." << endl;
}

catch (const blah2 &ex)
{
cout << "blah2 exception." << endl;
}

catch (...)
{
cout << "unknown exception." << endl;
}

Can one get for example the line number where the
unknown exception was thrown?

No.

a) All information used at the point of the catch has to be stored in the
thrown object (simply because that is the only one not subject to stack
unwinding). And, for all you know, what is caught in the (...) catch clause
could be a char.

b) If you find yourself wishing for that option, chances are that your
design needs fixing. What is the underlying problem you are trying to
solve?
I compiled a huge project of someone else.
The program's main() ends like that given above.
Too bad, since it is a huge project it seems not easy
to find the location of that error. :-(

Oct 12 '08 #3
Adem wrote:
"Kai-Uwe Bux" <jk********@gmx.netwrote:
>Adem wrote:
Is it possible to get some info about an unknown exception,
ie. the "catch (...)" case below:

catch (const blah1 &ex)
{
cout << "blah1 exception." << endl;
}

catch (const blah2 &ex)
{
cout << "blah2 exception." << endl;
}

catch (...)
{
cout << "unknown exception." << endl;
}

Can one get for example the line number where the
unknown exception was thrown?

No.

a) All information used at the point of the catch has to be stored in the
thrown object (simply because that is the only one not subject to stack
unwinding). And, for all you know, what is caught in the (...) catch
clause could be a char.

b) If you find yourself wishing for that option, chances are that your
design needs fixing. What is the underlying problem you are trying to
solve?

I compiled a huge project of someone else.
The program's main() ends like that given above.
Too bad, since it is a huge project it seems not easy
to find the location of that error. :-(
Running that thing in a debugger might help. Most can give you a stack
trace. That way, you can find the location where the throw happens.
Best

Kai-Uwe Bux
Oct 12 '08 #4
On Oct 12, 3:50 pm, "Adem" <for-usenet...@alicewho.comwrote:
Is it possible to get some info about an unknown exception,
ie. the "catch (...)" case below:

catch (const blah1 &ex)
{
cout << "blah1 exception." << endl;
}

catch (const blah2 &ex)
{
cout << "blah2 exception." << endl;
}

catch (...)
{
cout << "unknown exception." << endl;
}

Can one get for example the line number where the
unknown exception was thrown?
No, unless you equip the program to do so (add relevent catch clauses
to capture other specific exceptions). In the case where standardized
exceptions come into play, at least add a catch block for
std::exception. If coders stuck to using the existing hierarchy, life
would be much simpler, ie:

#include <iostream>
#include <stdexcept>

// std::runtime_error is a derivative of std::exception
class SomeException
: public std::runtime_error
{
public:
SomeException( const char* ps )
: std::runtime_error( ps ) { }
};

int main()
{
try
{
throw SomeException("error in main()");
}
catch( const std::exception& e )
{
std::cout << e.what() << std::endl;
}
catch( ... )
{
std::cout << "unknown exception\n";
}
}

/*
error in main()
*/
Oct 12 '08 #5
On Oct 12, 10:46 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Adem wrote:
I compiled a huge project of someone else.
The program's main() ends like that given above.
Too bad, since it is a huge project it seems not easy
to find the location of that error. :-(

Running that thing in a debugger might help. Most can give you a stack
trace. That way, you can find the location where the throw happens.
Commenting the catch(...) clause (temporarily) out may give the
debugger and you an easier time in locating the throw point.
If an exception is not caught at all, the debugger may kick-in
immediately when the throw-expressing is to be executed.
If there is a matching catch-clause, the debugger can only kick-in
when it hits a manually set breakpoint, which you can only set
correctly if you already know where the exception might be coming
from.
>
Best

Kai-Uwe Bux
Bart v Ingen Schenau
Oct 13 '08 #6
On Oct 12, 10:04 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
Adem wrote:
Is it possible to get some info about an unknown exception,
ie. the "catch (...)" case below:
[...]
No.
a) All information used at the point of the catch has to be
stored in the thrown object (simply because that is the only
one not subject to stack unwinding). And, for all you know,
what is caught in the (...) catch clause could be a char.
b) If you find yourself wishing for that option, chances are
that your design needs fixing. What is the underlying problem
you are trying to solve?
Most likely, he's dealing with a poorly documented third party
library. Which is throwing exceptions without documenting the
fact.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 13 '08 #7
James Kanze wrote:
On Oct 12, 10:04 pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:
>Adem wrote:
>>Is it possible to get some info about an unknown exception,
ie. the "catch (...)" case below:

[...]
>No.
>a) All information used at the point of the catch has to be
stored in the thrown object (simply because that is the only
one not subject to stack unwinding). And, for all you know,
what is caught in the (...) catch clause could be a char.
>b) If you find yourself wishing for that option, chances are
that your design needs fixing. What is the underlying problem
you are trying to solve?

Most likely, he's dealing with a poorly documented third party
library. Which is throwing exceptions without documenting the
fact.
Or, he could be dealing with Windows, which throws (...) for system errors.
Oct 13 '08 #8
"Adem" <fo***********@alicewho.comkirjutas:
catch (const blah2 &ex)
{
cout << "blah2 exception." << endl;
}

catch (...)
{
cout << "unknown exception." << endl;
}
[...]
I compiled a huge project of someone else.
The program's main() ends like that given above.
Too bad, since it is a huge project it seems not easy
to find the location of that error. :-(
This is more a debugging problem and thus depending on the environment.
If this is on Windows, then access violations and other thingies can end
up in catch(...). You can use the set_se_translator() function to
intercept and translate those, if needed.

Alternatively, each decent debugger should be able to break the program
execution in the spot when any exception is thrown, although the feature
might be well hidden ;-) E.g. for gdb you need the command: b __cxa_throw

Regards
Paavo
Oct 15 '08 #9
On Sun, 12 Oct 2008 21:50:53 +0200, "Adem"
<fo***********@alicewho.comwrote:
>Can one get for example the line number where the
unknown exception was thrown?
Here's one creative approach...

1. Make damn sure you have a safe unmodified copy of the original
source. Visual differencing tools are also likely to come in
handy.

On Windows, I'd just make a temporary subversion repository and
commit the original sources, using TortoiseSVN. That makes it easy
to diff any changes I make in the working copy.

2. Search all files, and replace every throw with some other code,
such as printing the value of __LINE__ then exiting. Anything
along those lines - the details will depend on the platform and
the application.

3. Run, check the exception that gets thrown, and restore each
exception throw when you're sure it's not the problem (exceptions
are not always errors, or at least they may already be handled
correctly).

You're far better off with a debugger, but this kind of approach can
help at times.
BTW - commenting out your catch(...) blocks may also help when
debugging. It converts a caught exception into an uncaught one, which
the debugger is more likely to break at by default.

Oct 16 '08 #10

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

Similar topics

10
by: Frank | last post by:
Using Python 2.2.2, I want to catch all exceptions from "socket.gethostbyaddr(ip)" From IDLE, I can generate: >>> socket.gethostbyaddr('1.2') Traceback (most recent call last): File...
4
by: Larry Tate | last post by:
I am wanting to get those cool html error pages that ms produces when I hit an error in asp.net. For instance, when I get a compilation error I get an html error page that shows me the ...
5
by: Lars-Erik Aabech | last post by:
Hi! Guess it's my day again.. Tried to deploy a test release of a new asp.net web today, and got a terrible error. The web is running swell on three development computers, but when it's copied...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
1
by: Greg | last post by:
My app makes a call to a remote server (about which I know relatively little) using Webclient.DownloadData. This is done once every 51/2 mins and is called by code within a worker thread. 95% of...
0
by: buntyindia | last post by:
Hi, I have a very strange problem with my application. I have developed it using Struts. I have a TextBox With Some fixed value in it and on Submit iam passing it to another page. <html:form...
3
by: ravit | last post by:
Hello All, I am trying to execute an application that is developed using eclipse libraries. Jface, SWT , etc. While I execute the application , i have received an exception which I am unable...
1
by: khatarnakkhatri | last post by:
java.net.BindException: Address already in use: JVM_Bind at java.net.PlainSocketImpl.socketBind(Native Method) at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359) at...
1
by: viswanathtvs | last post by:
java.util.NoSuchElementException javax.faces.el.EvaluationException: java.util.NoSuchElementException at...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
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...
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...

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.