Unhandled Exception

This is a discussion on Unhandled Exception within the C++ Programming forums, part of the General Programming Boards category; Hi! I'm using windows 98 and Turbo C++. Is there a way to keep from getting the following error message: ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    2

    Wink Unhandled Exception

    Hi!
    I'm using windows 98 and Turbo C++.
    Is there a way to keep from getting the following error message:

    ------------------------------------
    Unhandled Exception
    !
    General Protection Exception
    0x12CF:0x437B

    DATATEST(1) 0x12CF:0x437B Processor
    Fault

    [OK]
    ------------------------------------

    Processor Fault? I know I only have 24MG of RAM
    which by today's standards is Neolithic in computer years.
    It couldn't be RAM could it?

    Also, I was under the impression that fflush(stdin);
    was supposed to empty the data and make room for correct data... I'm wrong, aren't I?

    heres a snippet of code and pseudo-code for this program (its too long to post the whole thing so I put this much which compile fine for me)
    Now if the use 'misbehaves' and types in like 120 characters,
    I get that error message. Please enter too many characters to see what I mean:


    // filename: 'datatest.cpp'

    #include<iostream.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>
    #include<string.h>

    main() {

    char filename[40];
    char firstname[30];
    FILE *handle;

    // 1. ask for path and filename:

    cout << "Enter The Full MS-DOS Path Of The File You Need To Open\n";
    gets(filename);
    clrscr();

    // 2 & 3. open file and error check to see if it opens:

    if ((handle = fopen(filename, "a")) == NULL)
    {
    perror("filename (fopen)");
    exit(EXIT_FAILURE); // same as exit(1);
    }

    else
    {
    cout << "File Opened Successfully.\n";
    cout << "Press Any Key\n";
    getch();
    clrscr();
    }

    // 4. ask for name

    fflush(stdin);
    cout << "First Name:\n";
    gets(firstname);

    while (strlen(firstname) > 30)
    {
    fflush(stdin);
    cout << "\n\nRe-Enter First Name (less than 30 char):\n";
    gets(firstname);
    }


    // 5. append information to a file:

    fputs(firstname, handle);
    fputs("\n", handle);

    // 6. close file & exit:

    fclose(handle);
    exit(0);
    return 0;
    }


    Thankyou!

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >Also, I was under the impression that fflush(stdin);
    was supposed to empty the data and make room for correct data... I'm wrong, aren't I?

    Yes, it's undefined.

    >Now if the use 'misbehaves' and types in like 120 characters,

    Unless you allocate enough room to for the string before it's entered a possible outcome is a crash. I believe gets() is frowned upon by those that use C style i/o, so you probably shouldn't use it (look up fgets(), which allows you to limit the amount of characters extracted from stdin before it's too late).

    Also, main() returns an int, just because you've got a Neolithic computer doesn't mean you have to write Neolithic code. You don't need to call exit(0) before returning from main(), and unless you're careful you may get into trouble by mixing C and C++(specific) i/o.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-11-2006, 06:46 PM
  2. I got an unhandled exception!!
    By LegendBreath in forum Game Programming
    Replies: 7
    Last Post: 04-19-2005, 02:55 PM
  3. Unhandled exception: User breakpoint
    By glUser3f in forum C++ Programming
    Replies: 3
    Last Post: 10-02-2003, 05:20 PM
  4. unhandled exception error
    By trends in forum C++ Programming
    Replies: 4
    Last Post: 11-15-2002, 06:54 PM
  5. Unhandled exception
    By pdstatha in forum C++ Programming
    Replies: 1
    Last Post: 06-22-2002, 07:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21