Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2007

Tip: Looking for answers? Try searching our database.

Exception type

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maxim - 16 Feb 2007 23:48 GMT
Hi, All!

How do I get unmanaged exception type in the catch block. Here's the piece
of code to clarify my question.

try
{
  throw int(1);
}
catch(Exception^ ex)
{
............
}

How do I get the type (int) and the value (1) of the exception thrown?

Thanks in advance
Tamas Demjen - 17 Feb 2007 00:15 GMT
> try
> {
[quoted text clipped - 6 lines]
>
> How do I get the type (int) and the value (1) of the exception thrown?

I don't think System::Exception contains enough type information about
unmanaged exceptions. You have to catch int as an unmanaged exception.

You should always catch unmanaged exceptions first, then managed ones,
like this:

try
{
   throw int(10);
   //throw std::exception("a"); // try this too
}
catch(std::exception& ex)
{
   Console::WriteLine("std::exception: " + gcnew String(ex.what()));
}
catch(int value)
{
   Console::WriteLine("int: " + value.ToString());
}
catch(Exception^ ex)
{
   Console::WriteLine("Exception^: " + ex->Message);
}

It doesn't matter if you catch int or std::exception first, but
Exception^ goes last. Also, the most derived type in the hierarchy goes
first:

try
{
}
catch(std::runtime_error& )
{
}
catch(std::exception& )
{
}

Tom
Maxim - 17 Feb 2007 00:47 GMT
Thanks, Tom

>> try
>> {
[quoted text clipped - 45 lines]
>
> Tom

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.