| | |
Abnormal Program Termination Problem
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2009
Posts: 2
Reputation:
Solved Threads: 0
The output of the code below is:
start
Caught One! Ex. #: 1
Caught One! Ex. #: 2
Abnormal Program Termination
I don't understand why the exception isn't caught.
start
Caught One! Ex. #: 1
Caught One! Ex. #: 2
Abnormal Program Termination
I don't understand why the exception isn't caught.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; // Different types of exceptions can be caught. void Xhandler(int test) { try{ if(test) throw test; else throw "Value is zero"; } catch(int i) { cout << "Caught One! Ex. #: " << i << '\n'; } catch(char *str) { cout << "Caught a string: "; cout << str << '\n'; } } int main() { cout << "start\n"; Xhandler(1); Xhandler(2); Xhandler(0); Xhandler(3); cout << "end"; return 0; }
use a typecast in the throw tag
it should work. I have tried in my machine by using it.
C++ Syntax (Toggle Plain Text)
throw (char *)"Value is zero";
it should work. I have tried in my machine by using it.
If at all you want to throw string literals, remember that they are const char* not simply char*. So refactor your code as:
But then, before you find throwing string literals very comfortable, read this article http://www.informit.com/articles/art...30642&seqNum=5
CPP Syntax (Toggle Plain Text)
void Xhandler(int test) { try { if (test) throw test; else throw "Value is zero"; } catch (int i) { cout << "Caught One! Ex. #: " << i << '\n'; } catch (const char *str) { cout << "Caught a string: "; cout << str << '\n'; } }
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
![]() |
Similar Threads
- Microsoft Word abnormal termination (Windows Software)
- Beginer struct problem! (C)
- 2 PROBLEMS/ C++ run time libary and also i expor application error (Troubleshooting Dead Machines)
- Wireless Internet is Terminated in an Abnormal Way!!! (Networking Hardware Configuration)
- problem with wireless connection? (Networking Hardware Configuration)
- "The Sims" visual C++ runtime error, what shall i do? (Windows Software)
- Abnormal program termination (Windows NT / 2000 / XP)
- Problem trying to run old fortran based program in win xp (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: wanted solution
- Next Thread: Allegro, without graphics card
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





