try catch question

hi every body . why this code is wrong ? and how to fix it ?

1
2
3
4
5
6
7
8
try
{
throw; // i want to throw catch block . but i dont want define variable!
// i want just throw into first catch block . like __leave in __try/__finally
}
catch (...)
{
}
You have to throw something that can be catched. Ever tried catching something that's not there?

You don't actually need to declare a variable, you can just

 
throw std::runtime_error("Short description of your problem");


Or, if you really just want to randomly throw something
 
throw 1;


You can actually use throw without an expression behind it, but that's only allowed in catch blocks, and only rethrows the catched exception.
Topic archived. No new replies allowed.