Re: Exceptions Class...
On Jan 31, 10:45 pm, TheGunslinger <mikiesrunsbaal....@sbcglobal.net>
wrote:
On Mon, 31 Jan 2011 09:04:30 CST, yabo <max...@altribe.org> wrote:
On 01/31/2011 02:38 PM, TheGunslinger wrote:
PLEASE, tell me I an in error. Please, direct me to good reference on
the exceptions classes.
There are standard exceptions which inherit from std::exception:
http://cplusplus.com/reference/std/exception/
For example, std::runtime_error:
http://cplusplus.com/reference/std/stdexcept/runtime_error/
Not much there???
Enough.
Seems like each programmer has to write their own exception class?
If they have special needs, yes. For a lot of applications,
just runtime_error suffices.
I really was hoping there was something more:: a fully developed STD
exception class that covered all the generic errors one might
encounter?
Most applications I've seen find the standard exceptions more
than enough, and don't even use all of them.
Such as
try{...}catch(IOException ioe){...}
for input/output exceptions from the console.
What input/output exceptions? If you want them, there is
std::ios_base::failure, but exceptions are generally not a very
good way of handling I/O errors.
Appears that I must write an exception class which extends or
overloads the <exception> class of STD C++?
**Please forgive syntax as I am coming from an OOP/JAVA environment
and we are doing OOP/C++ as a 2nd semester
Java is a good example of how not to do things in this case.
Different types of "errors" require different types of handling:
in some cases, aborting is the only appropriate solution, in
others, exceptions are appropriate, and in a lot, return codes
are the most appropriate solution.
-------------------------------------------------------
#include <iostream>
#include <exception>
using namespace std;
#ifndef myExceptionClass.cpp
#define myExceptionClass.cpp
class myExceptionClass **extends exception{
code here
}; //End class definition
#endif
----------------------------------------------------
The above code is similar to what I would use under JAVA.
Perhaps, someone can re-write errors to demonstrate correct C++
syntax.
What kind of errors? There is no one right solution. It all
depends on the type of error.
--
James Kanze
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]