try catch exceptions
-
hi, for(int i = 0;i < n; i++) { try { //......... } catch(exception e) { //........ } } In tha above code,in catch block im printing some error message after the for loop terminated.my problem is when the for loop get terminates,im having the last error message only(the catch is called 2 times,so i need to display 2 error messages)... pls help me...
-
hi, for(int i = 0;i < n; i++) { try { //......... } catch(exception e) { //........ } } In tha above code,in catch block im printing some error message after the for loop terminated.my problem is when the for loop get terminates,im having the last error message only(the catch is called 2 times,so i need to display 2 error messages)... pls help me...
Gomathy_84 wrote:
im printing some error message after the for loop terminated
What do you mean by printing exactly ? Print on the console with printf ? Furthermore, you don't print after the for loop is terminated but in the loop itself.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
hi, for(int i = 0;i < n; i++) { try { //......... } catch(exception e) { //........ } } In tha above code,in catch block im printing some error message after the for loop terminated.my problem is when the for loop get terminates,im having the last error message only(the catch is called 2 times,so i need to display 2 error messages)... pls help me...
From what I understand, you're collecting error message inside the catch block and then displaying it after the loop terminates. If so you will need to collect multiple strings. You can do this using a vector of strings.
std::vector vstrErrors;
try
{
}
catch(std::exception e)
{
vstrErrors.push_back(e.what());
}«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
hi, for(int i = 0;i < n; i++) { try { //......... } catch(exception e) { //........ } } In tha above code,in catch block im printing some error message after the for loop terminated.my problem is when the for loop get terminates,im having the last error message only(the catch is called 2 times,so i need to display 2 error messages)... pls help me...
In general it's best to catch exceptions by reference, generally a
const
reference.try
{
// Exceptional stuff goes here...
}
catch (const exception &e)
{
// Handle exception here...
}Steve
-
From what I understand, you're collecting error message inside the catch block and then displaying it after the loop terminates. If so you will need to collect multiple strings. You can do this using a vector of strings.
std::vector vstrErrors;
try
{
}
catch(std::exception e)
{
vstrErrors.push_back(e.what());
}«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
From what I understand, you're collecting error message inside the catch block and then displaying it after the loop terminates. If so you will need to collect multiple strings. You can do this using a vector of strings.
std::vector vstrErrors;
try
{
}
catch(std::exception e)
{
vstrErrors.push_back(e.what());
}«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)here,im having seperate exception class like connectionException class.I derived it from std::exception. In the place of throw ..i wrote as throw connectionException(...some error message). In the place of Catch...how to catch my class exception and covert into std::exception??? Thanx.
-
here,im having seperate exception class like connectionException class.I derived it from std::exception. In the place of throw ..i wrote as throw connectionException(...some error message). In the place of Catch...how to catch my class exception and covert into std::exception??? Thanx.
This should do it. This is the C++ concept of "a base class object can reference a derived class object".
catch (connectionException& ce)
{
std::exception& e = ce;
}«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)