Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C++ Programming

Exception Handling


Hi,

I was wondering if there is any way to catch exceptions without
knowing in advance what errors may occur.

What I mean to say is that is it possible to use try {} on a bunch of
lines and catch ANY exception that might have occurred within those
few lines without the program crashing first ?

Thanks a ton,
Speed.

On 4 Juni, 13:39, Speed <lostandha@gmail.com> wrote:

> Hi,

> I was wondering if there is any way to catch exceptions without
> knowing in advance what errors may occur.

> What I mean to say is that is it possible to use try {} on a bunch of
> lines and catch ANY exception that might have occurred within those
> few lines without the program crashing first ?

There are two options, if you know that all exceptions that might
occur are subclasses of some common base-class (like std::exception)
you can catch the common base-class:

catch (std::exception& e)  // Notice the &
{
  std::cout << e.what() << std::endl;

}

If that does not work you can use (...) to catch anything that is
thrown, however if you do you can not get any information about it,
not even the type:

catch (...)
{
  std::cout << "An error occured!" << std::end;

}

--
Erik Wikstrm
Thanks a ton. But what do I need to throw in the try {}.
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc