Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

tryin to GetErrorMessage(...) from CFileException cause an assertion.

Posted on 2003-03-27
5
Medium Priority
?
1,980 Views
Last Modified: 2007-12-19
catch(CFileException  *ex)
{
     TCHAR   szCause[255];          
     ex->GetErrorMessage(szCause,255);
        ex->Delete();
}

when the program enter the catch block and try to execute GetErrorMessage then an exception occur which cause a popup message "Debug assertion failed!" to appear.
I am using a console application project with MFC in DLL.

0
Comment
Question by:yaroni188
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Kocil
ID: 8216364
catch(CFileException  ex)
{
    TCHAR   szCause[255];          
    ex.GetErrorMessage(szCause,255);
}
0
 
LVL 5

Accepted Solution

by:
Kocil earned 760 total points
ID: 8216390
Sorry, I though it was Java :)
here it is for C++

catch(CFileException  *ex)
{
    TCHAR   szCause[255];          
    ex->GetErrorMessage(szCause,254);
    ex->Delete();
}
0
 

Expert Comment

by:RattleSnake
ID: 8216435
If nothing helps, you might want to try this wrapper for FormatMessage I coded a while ago and pass the error code to it. Not sure if this would solve your problem:

CString GetLastErrorMessage(DWORD dwErr)
{
    try
    {
        LPVOID lpMsgBuf;

        DWORD dwError   =  dwErr ? dwErr : GetLastError();

        DWORD dwFlags   =  FORMAT_MESSAGE_ALLOCATE_BUFFER    |
                           FORMAT_MESSAGE_FROM_SYSTEM        |
                           FORMAT_MESSAGE_IGNORE_INSERTS;

        DWORD dwLang    =  MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT);

        DWORD dwBytes   =  FormatMessage(dwFlags,NULL,dwError,dwLang,
                             (LPTSTR) &lpMsgBuf, 0, NULL);

        if (dwBytes == 0) {
            return CString("Unknown");
        }

        CString sMessage((char*)lpMsgBuf);
        LocalFree(lpMsgBuf);
        return sMessage;
    }

    catch (...)
    {
        return CString("Unknown");
    }
}


And then:

catch(CFileException *e)
{
    CString err = GetLastErrorMessage(e->m_lOsError);
}

0
 
LVL 9

Expert Comment

by:tinchos
ID: 9551248

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: Kocil

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question