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

catching unmanaged c++ exceptions

Hi,

How do i catch an unmanaged c++ exceptions ?
right now i can catch the System.Runtime.InteropServices.SEHException and
System.Exception exceptions , but i wan't to catch myException unmanaged
class , how do i do this ?

Thanks.
Nov 17 '05 #1
2 5974
Write a wrapper managed class for your C++ component. And create your own
exception class
Assume your unmanaged code contains a method like foo

void foo(){}

In wrapper class implement foo as ;
void foo()
{
try
{
//Call unmanaged foo here
}
catch(Exception ex)
{
throw new MyException(ex);
}
}

In all around your code you should handle only MyException for all unmanaged
exceptions...

HTH
--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET

"yaron" <ya***@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hi,

How do i catch an unmanaged c++ exceptions ?
right now i can catch the System.Runtime.InteropServices.SEHException and
System.Exception exceptions , but i wan't to catch myException unmanaged
class , how do i do this ?

Thanks.

Nov 17 '05 #2
> How do i catch an unmanaged c++ exceptions ?

You can try a "general catch clause":

try
{
...
}
catch // nothing here
{
}

The language spec says it matches any exception type, but is slightly vague
on the details. Here is a quote:

"Some environments, especially those supporting multiple languages, might
support exceptions that are not representable as an object derived from
System.Exception, although such an exception could never be generated by C#
code. In such an environment, a general catch clause might be used to catch
such an exception. Thus, a general catch clause is semantically different
from one that specifies the type System.Exception, in that the former might
also catch exceptions from other languages."
Nov 17 '05 #3

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

Similar topics

1
by: Rolf | last post by:
I understand a compilation error occurs when a method that throws no exceptions is the only code in a try block. What I don't understnad is why I can specify the catching of an Exception for a...
2
by: Keith Bolton | last post by:
I am handling exceptions currently using try, except. Generally I don't handle specific exceptions and am catching all. Then if an exception occurs, I would like to capture that error string....
2
by: Bret Pehrson | last post by:
Suppose the following: // Unmanaged code class UnmanagedException /* not visible outside of unmanaged code */ { }; void DoSomething() /* visible (exported) to managed code */ { throw new...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
12
by: Vasco Lohrenscheit | last post by:
Hi, I have a Problem with unmanaged exception. In the debug build it works fine to catch unmanaged c++ exceptions from other dlls with //managed code: try { //the form loads unmanaged dlls...
2
by: yaron | last post by:
Hi, How do i catch an unmanaged c++ exceptions ? right now i can catch the System.Runtime.InteropServices.SEHException and System.Exception exceptions , but i wan't to catch myException...
3
by: TheLetti | last post by:
Hello out there, is there any possibility for me to catch or avoid crashes caused within unmanaged code? The situation: I'm writing a managed wrapper in MC++, and in there I use some...
7
by: Derek Schuff | last post by:
I'm sorry if this is a FAQ or on an easily-accesible "RTFM" style page, but i couldnt find it. I have some code like this: for line in f: toks = line.split() try: if int(toks,16) ==...
5
by: Simon Tamman | last post by:
I have an object named DisasterRecovery. The Ctor of this object is this: private DisasterRecovery() { Application.ThreadException+= new...
12
by: Karlo Lozovina | last post by:
I'm not sure if Python can do this, and I can't find it on the web. So, here it goes: try: some_function() except SomeException: some_function2() some_function3() ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
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?

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.