| | |
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 beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





