473,811 Members | 3,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(CExceptio n msg) {
cerr << msg.ReportError () << endl;
}
catch(CExceptio n *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 1878
* 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(CExceptio n msg) {
cerr << msg.ReportError () << endl;
}
catch(CExceptio n *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
5295
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 is that when an exception is raised, the destruction of locals appears to be deferred to program exit. Am I missing something? Is this behaviour by design? If so, is there any reason for it? The only rationale I can think of is to speed up...
1
2156
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 send to the database a script file to run, as done by: "@FullPath\FileName" in SQL PLUS ? If not, then I need your help with something else: I tried to send to the database the script file's content, in order to run the commands in it (create...
1
5562
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 the runtime system during the execution of an image. The profiler receives notifications each time a function is entered or exited, as well as when other events occur that are of interest to the
2
3509
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 effectively. I've been looking in the Help / Index for each Method's documentation, and looking at the listed Exceptions. I'm finding a number of methods with no Exceptions specified. Does that mean there is no possible Exception for that method?...
4
4787
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 and the only way get it up and running again is to kill the aspnet_wp.exe process. When the debugger hangs there is almost no CPU load, so it doesn't seem to be any hidden eternal loop or anything like that. I have tried to reinstall IIS and...
1
2393
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 look for when evaluating someone's code is a try/catch block. While it isn't a perfect indicator, exception handling is one of the few things that quickly speak about the quality of code. Within seconds you might discover that the code author...
1
1338
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 questions are: 1) is it possible to disable the exception interception mechanism so that the debugger is usable (note that the exception handling to continue with the Exceptions dialogue does not do this)
81
4581
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 less virtual memory. Are other people experiencing this same problem?
0
6505
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 NullPointerException or ArrayIndexOutOfBoundsException. All of these extend the basic class Exception. In general, you can sort Exceptions into two groups: Checked and unchecked Exceptions. Checked Exceptions are checked by the compiler at compilation time. Most...
0
9722
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
9603
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
10644
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...
1
10393
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
9200
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
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
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
3
3015
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.