GameCodeError

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • GameCodeError

      Need a bit of help with Exception handling

      I have made a class for exception handling using the GameCodeError as a prototype:

      From CheckHardDisk, I am throwing

      <code>
      if (diskfree.avail_clusters < neededClusters)
      {
      // if you get here you don’t have enough disk space!
      throw errorTypes(EC_INIT_NOT_ENOUGH_DISK_SPACE);
      }
      </code>

      and the catch statement is this:

      <code>
      try
      {
      CheckHardDisk(2000000000000000);
      }
      catch (int EC_INIT_NOT_ENOUGH_DISK_SPACE)
      {
      if (EC_INIT_NOT_ENOUGH_DISK_SPACE)
      {
      MessageBoxW(hWnd, L"Not Enough Disk Space, please delete some data and try again!", L"ERROR", MB_OK);
      return E_FAIL;
      }
      }
      </code>

      I am getting the following error in the CheckHardDisk function after the exception is thrown:

      Unhandled exception at 0x7c812afb in MyApp.exe: Microsoft C++ exception: errorTypes at memory location 0x0012fb18..

      Any ideas?
    • Just to verify, "errorType(EC_INIT_NOT_ENOUGH_DISK_SPACE)" returns an int right? Also given that your catch statement will catch any integer, you should be comparing the value it catches to your constant, which you seem to be trying to use as the variable name. Not really sure why that's not giving you a compile error either...

      Source Code

      1. try
      2. {
      3. CheckHardDisk(20000000000000000000);
      4. }
      5. catch(int error)
      6. {
      7. if(error == EC_INIT_NOT_ENOUGH_DISK_SPACE)
      8. {
      9. MessageBoxW(hWnd, L"Not Enough Disk Space, please delete some data and try again!", L"ERROR", MB_OK);
      10. return E_FAIL;
      11. }
      12. }
      Display All