Menu

Exception Handling Question!? Dev-C++4

2002-10-21
2012-09-26
  • Nobody/Anonymous

    Hello forum,

    I've tried this Code:

    //...
    try
    {
        //somewhat happens
        if(somewhat has happened)   throw "somewhat";

    }
    catch(char  *str)
    {
       printf("%s has happened!!", str);
    }
    catch(...)
    {
       printf("Exeption not of type char*  !!");
    }

    The strange thing is, that    catch(char *str)   is not executed, but catch(...).

    If i would have written:

    //...
    char *ThrowStr = "TextTextText";
    throw ThrowStr;
    //...

    , then       catch(char *str)    would have been tested.

    In some Tutorials they write only the first syntax.

    But why doesn't it work on my Dev-C++4 ???

    Thanks , Tom.

     
    • Nobody/Anonymous

      Without doing any testing I'm going to have a stab and say that a string like "somewhat" is not a char * but it is a const char * and therefore is not caught by your catch(char *) statement.

      Try it with catch (const char*) and let me know.

      BlakJak :]

       
    • Nobody/Anonymous

      Thanks, BlakJak  ;]

      It really works!

      Tom 8)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.