| | |
Windows' Default Exception Message
Thread Solved |
Hey guys,
How do I disable/get rid of that default exception message windows shows when you have an "unhandled" exception in your program?
Here's my example code (sorry for not limiting the code's size to the problem only, it's readable enough I think):
So, the exception gets thrown at line 40, handles it there nicely. Then it rethrows it to main, which in term calls (my own) terminate() which is also good, but then windows' message still pops up:
I want to get rid of those last 2 lines, my programs will not have a support team. 
Thanks in advance,
Nick
PS: Obviously, you should set the filepath in main to some big file that you're PC can't handle, or just alter the new[] (in load_file()) to have some big big big number. You might want to disable your swap before you do this though!
How do I disable/get rid of that default exception message windows shows when you have an "unhandled" exception in your program?
Here's my example code (sorry for not limiting the code's size to the problem only, it's readable enough I think):
cpp Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> #include <new> /* load_file(filepath, destination) -Returns whether it succeed or not. True meaning succeeded. -Takes a path and writes to a std::string, completely memory safe. */ bool load_file(const char *filepath, std::string &dest) throw (std::bad_alloc) { using namespace std; ifstream file; file.open(filepath, ios::binary); if (!file.good()) { cerr << "Fatal error while opening file." << endl; return false; } //get filesize in bytes from ifstream //seek end, get pointer, rewind file.seekg(0, ios_base::end); size_t file_size = file.tellg(); file.seekg(0, ios_base::beg); if (!file.good()) { cerr << "Fatal error while getting filesize." << endl; return false; } //read file in string from ifstream //allocate array, read file in array, set the term. null byte, set string to array char *file_content; try { file_content = new char [file_size+1]; } catch (bad_alloc &memException) { cerr << "Probably went out of memory while allocating " << file_size+1 << " bytes!" << endl; file.close(); throw; } file.read(file_content, file_size); file_content[file_size] = '\0'; dest = file_content; //clean up //close file, free array file.close(); delete[] file_content; return true; } void custom_terminate() { std::cerr << "--Aye, unrecoverable exception thrown!\n" << "Try doing what the messages say (if anything) and run the program again or ask someone with a bit more expertise to help you out." << std::endl; std::abort(); } int main() { using namespace std; set_terminate(custom_terminate); string file_content; load_file("C:\\Program Files (x86)\\SEGA\\Condemned - Criminal Origins\\Game\\CondemnedA.Arch00", file_content); return 0; }
So, the exception gets thrown at line 40, handles it there nicely. Then it rethrows it to main, which in term calls (my own) terminate() which is also good, but then windows' message still pops up:
C++ Syntax (Toggle Plain Text)
Probably went out of memory while allocating 2384200440 bytes! --Aye, unrecoverable exception thrown! Try doing what the messages say (if anything) and run the program again or ask someone with a bit more expertise to help you out. This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

Thanks in advance,
Nick
PS: Obviously, you should set the filepath in main to some big file that you're PC can't handle, or just alter the new[] (in load_file()) to have some big big big number. You might want to disable your swap before you do this though!
Last edited by Clockowl; Apr 14th, 2009 at 11:51 am.
![]() |
Similar Threads
- Explorer Restarting with MEssage as Buffer Overrun (Viruses, Spyware and other Nasties)
- WCF on IIS - Getting error trying to connect with certificate based authentication (ASP.NET)
- This page cannot be displayed error (Viruses, Spyware and other Nasties)
- Many problems... (Viruses, Spyware and other Nasties)
- Why app is looking for "Default.aspx" (ASP.NET)
- Login used to work (ASP.NET)
- Cannot access website (Viruses, Spyware and other Nasties)
- Maybe someone a whole lot smarter than I am can help (Viruses, Spyware and other Nasties)
- Windows XP Proffesional - Explorer problem (Windows NT / 2000 / XP)
- This ought to be simple - extra spaces (PHP)
Other Threads in the C++ Forum
- Previous Thread: List of arguments with boost program_options?
- Next Thread: c++ ???
Views: 559 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment basic beginner binary c++ c/c++ calculator char class classes code compile compiler constructor conversion convert count data delete desktop display dll dynamic encryption error file files fstream function functions game givemetehcodez graph graphics gui homework http iamthwee input int lazy linker list loop looping loops math matrix member memory multidimensional newbie number numbers object objects opengl output parameter pointer pointers problem program programming project python random read reading recursion recursive reference sort sorting spoonfeeding string strings struct student studio template templates text time tree variable vc++ vector video visual visualstudio win32 window windows winsock xml





