How to handle exception from function as we not develope that fuction() and dont kno what type of exception it will throw
-
Hello All, consider following code try { function(); } catch(//what typr should expect) { } fuction is develope from other one and he not mention the type of exception he returning.. ///////////////////////////////////////////////////// if i use this code catch(std::exception & s) { cout<<s.what(); } i get error in vs2008 Error is :-- This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Please help , thanks.
-
Hello All, consider following code try { function(); } catch(//what typr should expect) { } fuction is develope from other one and he not mention the type of exception he returning.. ///////////////////////////////////////////////////// if i use this code catch(std::exception & s) { cout<<s.what(); } i get error in vs2008 Error is :-- This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Please help , thanks.
-
Hello All, consider following code try { function(); } catch(//what typr should expect) { } fuction is develope from other one and he not mention the type of exception he returning.. ///////////////////////////////////////////////////// if i use this code catch(std::exception & s) { cout<<s.what(); } i get error in vs2008 Error is :-- This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Please help , thanks.
You left out the
throw()
operand. Throw tells the compiler that a function could throw an exception and thecatch()
operand and catches (handles) the exception thrown by thethrow()
operand.char *buf; try { buf = new char[512]; if( buf == 0 ) throw "Memory allocation failure!"; } catch( char * str ) { cout << "Exception raised: " << str << '\n'; }
-
Thanks for Reaply, But how can I get type of thown exception. whether he is throwing int,char*,of any user define data type. So that I can Identify what type of execption is occur.
-
Thanks for Reaply, But how can I get type of thown exception. whether he is throwing int,char*,of any user define data type. So that I can Identify what type of execption is occur.
You can't...I would suggest you don't use a function if you don't know what its public interface is...and it's exception throwing habits are part of that public interface, so don't use this one...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!