visual c++ - a small issue in using exception handling in c++ -


the below given simple exception program giving unhandled exception "microsoft c++ exception: int @ memory location 0x0012fe94..". getting error after function excep() returned. please can tell why error coming here. helpful if possible mistakes in code explained/analysed. learning code better.

i using visual c++ 2005.

#include <iostream> using namespace std;  int main () {    int excep(int);     throw excep(20);     return 0; }  int excep(int e) {      cout << "an exception occurred. exception nr. " << e << endl;     return 0;  } 

in line

throw excep(20); 

excep(20) called first, return value thrown, i.e. throw integer. equivalent to:

const int = excep(20); throw i; 

to idea how exception-snytax looks:

#include <iostream> #include <stdexcept> using namespace std;  int main () {    try {        //        throw std::runtime_error("test");    } catch (const std::exception &e) {        std::cout << "exception: " << e.what() << std::endl;    } } 

in practive: never throw not derived std::exception.

proposed readings:


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -