   possible exceptions and their handling
  HiI am trying to make a good class for handling exceptions, but I have already stucked at one point.#include <iostream>#include <exception>using namespace std;int main(){try{string str;str[20] = 'z';}catch(std::exception &ex){  cout << ex.what() << endl;}return 0;}What I am trying to do is to catch any exception and process it - output the error atleast, but It seems it is not the correct way to do. Can anyone help me out with this ?   
  catch (...){}is a catch all, though you don't have an actual exception object to process then   ;  Yes I know but where can I get a list of all possible exceptions for C++ ? If there is one.   ;  No, there is no list of all possible exceptions.  Anybody at any time can derive a new exception class.  You also are not required to throw exceptions deriving from std::exception (you can throw an int for example).Your exception code is perfectly fine the way it is.  We could get into arguments about whether such catch-all handlers are a good thing or not but that's a different issue.You seem to expect str[20] = 'z' to throw an exception.  This is not the case.  When you access characters using [] you don't get any bounds checking.  You might want to use str.at(20) instead.   ;  Ok thanks that does solve the problem. I have one more question. I found some examples on the net when derived from std::exception class was used. Although this example doesn't seem to work. Exception is undefined.Quote:class IException : public exception{};#include <iostream>#include <string>using namespace std;int main(){try{string str;str.at(20) = 'z';} //trying to catch std exception to my class but it failscatch(IException &ex){  cout << ex.what() << endl;}catch(int &ex){cout << "Exception: " << ex << endl;}catch(...){cout << "Undefined exception!"<< endl;}return 0;};  Be aware that not all error conditions will throw an exception.  An out of bounds memory access (segmentation fault/access violation) will not show up as any kind of exception.  This is something that occurs at an OS level.   ;Quote:Original post by Anonymous PosterBe aware that not all error conditions will throw an exception.  An out of bounds memory access (segmentation fault/access violation) will not show up as any kind of exception.  This is something that occurs at an OS level.True. For Windows google for "structured exception handling" or "SetUnhandledExceptionFilter", for Unix "signal"   ;Quote:Original post by DMINATOROk thanks that does solve the problem. I have one more question. I found some examples on the net when derived from std::exception class was used. Although this example doesn't seem to work. Exception is undefined.Quote:class IException : public exception{};*** Source Snippet Removed ***Remember exception is in the std namespace.  You should never put a "using namespace xyz" in a header file, because then you are forcing everything that includes it to use that namespace - which could end up in naming conflictsclass IException : public std::exception{};Though the naming of that class is kind of misleading - as "IException" implies an interface - where as this is just an empty specialisation of an exception (and to my eyes at least completely pointless).  You could just catch std::exception and that will catch all decendants anyway.   