C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 5th, 2003, 08:27 PM
Skydrop Skydrop is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 Skydrop User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
handling any exception in a try catch block?

Hello,

I have a situation where by I have functionA throwing exceptions, I don't really care about the kind of exceptions thrown from functionA just that there maybe many of them and of differing type.

I want to execute functionA and handle any exception thats thrown from executing functionA and just discard them, maybe make a note of them somewhere but thats beside the point.

Is it possible to make this water tight? .. no exceptions thrown in functionA will get out

functionA is inside of a win32 dll, it runs lots of code and the nature of what it does makes it unreliable. I am not using MFC and would like to keep this as standard as possible.

In Java the answer to the above question would be, put a try catch block round the function call and catch the Exception class:

try {
obj.functionA();
}catch(Exception e)
{
}

I can't seem to find any information relating to this, wether there is a base class for all the exceptions thrown to catch, is there? and will that catch all exceptions?

Thanks

Skydrop

Reply With Quote
  #2  
Old April 5th, 2003, 11:45 PM
7stud 7stud is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2001
Posts: 1,365 7stud User rank is Private First Class (20 - 50 Reputation Level)7stud User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 18 h 9 m 25 sec
Reputation Power: 14
Hi,

My book says,

catch(...)
{
}

will handle an exception of any type. In addition, it says that all exceptions defined in the standard library are derived from the standard class std::exception, so you can use a base class handler to catch any exceptions derived from std::exception,

catch(exeception& rEX)
{
}

Last edited by 7stud : April 5th, 2003 at 11:55 PM.

Reply With Quote
  #3  
Old April 6th, 2003, 05:52 AM
MJEggertson MJEggertson is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Seattle WA
Posts: 863 MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level)MJEggertson User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 sec
Reputation Power: 13
The elipsis (...) is the proper way to do it. Read up on what it's used for.

Basicly, it signifies an argument list of unknown type and quantity. Beyond using it for catch-all statements, you can also use it in function declarations that accept variable parameter types/quantities. Though it's rarely used in functions since it defeats the inherrent typesafety of C++, many stl functions are defined using them. Think functions that accept almost any number of arguments, like the printf() family...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > handling any exception in a try catch block?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap