April 5th, 2003, 09:27 PM
handling any exception in a try catch block?
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:
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?
April 6th, 2003, 12:45 AM
My book says,
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,
Last edited by 7stud; April 6th, 2003 at 12:55 AM.
April 6th, 2003, 06:52 AM
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...