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

Visual C++ Exceptions

It's been a while since I've used Visual C++ and I'm getting an exception
from an unknown source. I'm writing Java JNI code, calling Java from C++. Is
there any way to get more information about what's getting thrown? I've
tried to catch it with a variety of catch clauses with all sorts of types.
The only catch that works is catch(...). My catches look like:

catch(const string &msg) {
cerr << msg.data() << endl;
}
catch(const char * msg) {
cerr << msg << endl;
}
catch(CException msg) {
cerr << msg.ReportError() << endl;
}
catch(CException *msg) {
cerr << msg->ReportError() << endl;
}
catch(int msg) {
cerr << msg << endl;
}
catch(const runtime_error &err) {
cerr << err.what() << endl;
}
catch(const logic_error &err) {
cerr << err.what() << endl;
}
catch(const bad_exception &err) {
cerr << err.what() << endl;
}
catch(const exception &err) {
cerr << err.what() << endl;
}
catch(...) {
cerr << "unknown exception" << endl;
}
Mar 7 '06 #1
3 1861
* JCav:
It's been a while since I've used Visual C++ and I'm getting an exception
from an unknown source. I'm writing Java JNI code, calling Java from C++.


Visual C++ is off-topic here, largely. JNI is off-topic here, largely.
Except where there is some general standard C++ issue.

Please post to an appropriate group.

Since you're doing JNI, most probably your exception source is JNI, and
thus a Java programming group would be indicated (also, that library is
probably where you'll have to look for more exception information).
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 7 '06 #2
"Alf P. Steinbach" <al***@start.no> wrote in message
news:47************@individual.net...
* JCav:
It's been a while since I've used Visual C++ and I'm getting an exception
from an unknown source. I'm writing Java JNI code, calling Java from C++.


Visual C++ is off-topic here, largely. JNI is off-topic here, largely.
Except where there is some general standard C++ issue.

Please post to an appropriate group.

Since you're doing JNI, most probably your exception source is JNI, and
thus a Java programming group would be indicated (also, that library is
probably where you'll have to look for more exception information).


Actually, I think his actual question is OT here, I just don't have the
answer. The question being, if something is being thrown, how do you find
out what the type is of what's being thrown without knowing it before hand?

My only suggestion would be to throw it in a debugger and run it and see
where it's throwing.
Mar 7 '06 #3
GB
JCav wrote:
It's been a while since I've used Visual C++ and I'm getting an exception
from an unknown source. I'm writing Java JNI code, calling Java from C++. Is
there any way to get more information about what's getting thrown? I've
tried to catch it with a variety of catch clauses with all sorts of types.
The only catch that works is catch(...). My catches look like:

catch(const string &msg) {
cerr << msg.data() << endl;
You can just say

cerr << msg << endl;

The << operator is overloaded to handle string objects directly.
}
catch(const char * msg) {
cerr << msg << endl;
}
catch(CException msg) {
cerr << msg.ReportError() << endl;
}
catch(CException *msg) {
cerr << msg->ReportError() << endl;
}
catch(int msg) {
cerr << msg << endl;
}
catch(const runtime_error &err) {
cerr << err.what() << endl;
}
catch(const logic_error &err) {
cerr << err.what() << endl;
}
catch(const bad_exception &err) {
cerr << err.what() << endl;
}
The three exceptions above are all derived from the one you are catching
below. Since you are handling all of them the same way (printing the
result of what()), it is not necessary to catch them.
catch(const exception &err) {
cerr << err.what() << endl;
}
catch(...) {
cerr << "unknown exception" << endl;
}


This is non-standard, so off-topic here, but Visual C++ by default
arranges to throw a special C++ exception when certain illegal
operations, such as dereferencing a null pointer, are performed. This
exception is not derived from any accessible exception type, so you
can't catch it except by "..." as you did. To determine if this is what
is happening, you need to run your software under a debugger. I
recommend setting the appropriate compiler options to disable this
behavior. Then when such an operation happens, you will crash instead,
and you can elect to attach with a JIT debugger.

Gregg
Mar 7 '06 #4

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

Similar topics

16
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem...
1
by: Tom Rahav | last post by:
Hello all! I develop application in Visual Basic .NET and ORACLE database. My question is how do I "send" script file to the database using visual basic .net. Other words, is there any way to...
1
by: Chris Morse | last post by:
Does anyone know how to profile a VB.NET application? In the VS.NET 2003 docs, I found this: (BEGIN DOC COPY) "A code profiler is a software tool, implemented as a DLL, which is called by...
2
by: felecha | last post by:
I learned about Exceptions in School, and now that I'm building my first real application on the job, I'm going through it trying to analyze it for all possible Exceptions so I can handle them...
4
by: Martin Odhelius | last post by:
Hello, I have a very fustrating problems while debugging ASP.NET applications. When I am debugging and stepping thru code (with F10 or F11) Visual Studio some times suddenly just stop responding...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
1
by: simon | last post by:
I'm using VC++ 2003. My code throws lots of exceptions but the debugger's handling of these makes the program (and hence debugging process) unusably slow; this was not the case in VC++ 6. So my...
81
by: Peter Olcott | last post by:
It looks like System::Collections::Generic.List throws and OUT_OF_MEMORY exception whenever memory allocated exceeds 256 MB. I have 1024 MB on my system so I am not even out of physical RAM, much...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: 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:
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
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,...

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.