Caching Errors

This is a discussion on Caching Errors within the C++ Programming forums, part of the General Programming Boards category; Hi, it's me again I have an little Problem. i have to catch errors from an funktion. Sound simple but ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    5

    Caching Errors

    Hi,

    it's me again

    I have an little Problem. i have to catch errors from an funktion.

    Sound simple but isnt it as it seems to me.

    I'm using the freeimage libary to open CMYK TIFF files. It works fine if the files i want to open are for shure CMYK files but if not the Programm runs in an error

    "User Breakpoint called from code at 0x7789180c"

    So how can i catch this error and tell the User that hi had chosen an wrong file format.

    My first thought was an try catch block, but to catch something i have to throw it but cause it isn't my own function i coulndt throw anything.

    Hope for your help

    Joerg

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    I assume that by "wrong format", you mean that the user is trying to open a JPEG, or something...

    In this case, you should do some pre-testing of the file. You could read the file header, and if it's not identified as the correct TIFF format, display a message. This won't always work if it's a corrupted TIFF file.

    I don't know anything about TIFF file-headers (maybe you do)... But, in general, standardized file formats will have a header section.

    If you don't already have them, you can find the TIFF file format specifications at wotsit.org.

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I don't think you need to throw to catch an error, although I'm no expert (I really need to read up on exceptions...). Something like this should work, if it's really an exception being thrown by the function:
    Code:
    try
    {
         theFunction();
    }
    catch(int err)
    {
         if(err == THIS_ERROR)
              cout << "Error is this_error";
    }
    But "User breakpoint" sounds like a breakpoint is reached to me... you know, those red dots that appear beside a line of code when you select the line and hit F9 in MSVC I'm probably all wrong, but I like to talk so... heh, yeah.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    5
    i'm shure i have set no breakpoint The error only appears if there isn't loaded an tiff file or an non CMYK tiff file

    DougDbug The Problem occours only if the opend file isn't an tiff file oder an tiff file but not YMYK format. The way around i could do it i to open it an an normal tiff file an check if its in the CMYK format, close it again and open it as an CMYK tiff

    But i normaly write in delphi and there i would use try and exept to catch all errors. But in c++ i only find the try catch if there is an error postet by myself before. And i want to know if there is an way to catch any errors in an foreign fuction i user


    ( Sorry for my english, but i'm from germany, but i hope you understand what i mean )

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    As I said... try/catch works as long as the function you called, or a function that function calls, etc. throws an exception.
    Code:
    try
    {
         someForeignFunction();
    }
    catch(int err)
    {
         cout << "Error: " << err;
    }
    i'm shure i have set no breakpoint
    That's why I said:
    I'm probably all wrong, but I like to talk so... heh, yeah.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  6. #6
    verbose cat
    Join Date
    Jun 2003
    Posts
    209

    Re: Caching Errors

    Originally posted by joerghamster
    I'm using the freeimage libary to open CMYK TIFF files. It works fine if the files i want to open are for shure CMYK files but if not the Programm runs in an error

    "User Breakpoint called from code at 0x7789180c"

    So how can i catch this error and tell the User that hi had chosen an wrong file format.

    My first thought was an try catch block, but to catch something i have to throw it but cause it isn't my own function i coulndt throw anything.
    Since this is not your own function that is opening the (possible) .tiff file, what documentation is there for this specific function? Does it specify what return values you can expect from it when it's called? Is the program exiting while inside this function or does it come back to your code and then cause an error somewhere?

    If it doesn't have a return value to indicate it was successful, you may want to write a "pre-function" function to look at the header. If the "pre-function" indicates that the header is not valid, you would then tell the user the file isn't a valid .tiff and not call the provided function.

    Hope this helps!

    -jEssYcAt

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    5
    Thr Probelm is, that it ends in the function and doesn't reurn to the main code. so there arent any possible return values.

    but i think i have to write the prefunction if there is no other way

    but thanks for any help

  8. #8
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    Code:
    try
    {
          //code here
    }
    catch(...)
    {
        //handle error
    }
    I do beleive that this is how you can catch any exception that the function might throw.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 04:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 09:18 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM

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