0

My app was running fine until I tried to debug it with the Application Verifier. After that I started getting "First-chance exception... : An invalid handle was specified" and the issue seems to be in the "bailout.c" file in Pantheios:

hFile = CreateFileA("logging-bailout.txt"
                ,   GENERIC_WRITE
                ,   0
                ,   NULL
                ,   OPEN_ALWAYS
                ,   0
                ,   NULL); <--- this is where it crashes, line 442

And message:

First-chance exception at 0x7769f8cd in myapp.exe: 0xC0000008: An invalid handle was specified.


=======================================
VERIFIER STOP 0000000000000300: pid 0x3814: Invalid handle exception for current stack trace. 

    00000000C0000008 : Exception code.
    00000000111DE950 : Exception record. Use .exr to display it.
    00000000111DE460 : Context record. Use .cxr to display it.
    0000000000000000 : Not used.


=======================================
This verifier stop is continuable.
After debugging it use `go' to continue.

=======================================

Before the console just logged the exceptions that I got with Pantheios and I didnt really care too much about. However, now when the app crashes on the first occurrence of logging using Pantheios it's time for me to deal with this, but I'm not too sure sure how to.

I was following this guide when setting up my Pantheios: http://www.codeproject.com/Articles/27119/Using-Callback-Back-ends-with-the-Pantheios-Loggin

In every file I have logging I have the following lines in the source file:

#include <pantheios/pantheios.hpp>
#include <pantheios/inserters/boolean.hpp>
#include <pantheios/inserters/integer.hpp>
#include <Shared/logs.h>

logs.h contains:

#include <pantheios/implicit_link/core.h>
#include <pantheios/implicit_link/fe.simple.h>
#include <pantheios/implicit_link/be.WindowsConsole.h>

I also call pantheios::init(); before doing any logging.

I'm using Visual studio 2010 and are including the following lib-files under "Additional Dependencies":

$(PANTHEIOS_ROOT)\lib\pantheios.1.core.vc10.mt.debug.lib
$(PANTHEIOS_ROOT)\lib\pantheios.1.be.WindowsConsole.vc10.mt.debug.lib
$(PANTHEIOS_ROOT)\lib\pantheios.1.fe.simple.vc10.mt.debug.lib
$(PANTHEIOS_ROOT)\lib\pantheios.1.util.vc10.mt.debug.lib

However, all my logging looks like this:

First-chance exception at 0x750bb9bc in myapp.exe: Microsoft C++ exception: stlsoft::winstl_project::windows_exception at memory location 0x1822bda0..

20120423-104817.497: failed to write message to log file; given message follows: [myapp.Qt.Framework.13424, 23/04/2012 10:48:17.496 a.m.; Debug]: "some logging"

when calling pantheios::log(pantheios::debug, "some logging");

Then, all my logging is written to a "bailout"file in the same folder as the project. This worked before but it was a big bullet on my "To-do-list" (but a bit further down than other things).

So now my question is, how do I fix this? Followed every tutorial I can find but with no success. And why did my app decide to not accept this anymore after running the Ms Application Verifier? Makes no sense.

Community
  • 1
  • 1
chikuba
  • 4,229
  • 6
  • 43
  • 75

1 Answers1

2

First chance exceptions mean only that an exception was thrown. It does not mean you have a bug in your program, just that the debugger is showing you that an exception is being thrown, so you have a chance to examine it before it is propagated up the call chain. If the exception is caught by an exception handler (e.g. for logging), your application continues, otherwise the debugger gives you a second-chance exception notification to inform you that the application will exit due to an unhandled exception.

If you do not want to receive the first-chance exception notifications, you can turn it off in your debugger. This link may help on how to turn off exception handling in Application Verifier.

To work around this problem, turn off exceptions testing in Application Verifier. To do this, follow these steps:

1.Start Application Verifier.

2.Under Applications, click the GDI+ program that you want to test.

3.Under Tests, expand Basics.

4.Click to clear the Exceptions check box.

5.Run the GDI+ program that you want to test.

You can also configure the debugging tool to make sure that you do not experience a breakpoint in the debugging tool when an access violation occurs.

The alternative (turning off exception notification in MSVS) is via "Debug->Exceptions..."

Alternatively, if it is possible, make sure the exception does not get thrown in the first place. You will need to examine the nature of the exception (e.g. file not found) and fix the condition that is preventing the intended operation.

Given the nature/purpose of Application Verifier, I would suggest the latter approach: AV is telling you that something incorrect is going on that might have been ok previously, but can cause problems later on (depending on enviornment, circumstances, etc.)

Community
  • 1
  • 1
Attila
  • 28,265
  • 3
  • 46
  • 55
  • yeah i turned it of so now it doesnt crash anymore. however, i cant have that message in my logging since it makes it too hard to read. i still cant figure out how to get it to go away.. – chikuba Apr 29 '12 at 22:23
  • How do the first-chance exception messages get to be written in your custom log? If you are catching all exceptions and logging them, you could figure out what exception is thrown specifically and ignore it. The ideal solution would still be to fix the conditions that lead to the exception when calling `CreateFileA` in the first place – Attila Apr 30 '12 at 00:03
  • not logging the exception but the "20120327-112911.994: failed to write message to log file; given message follows: " in the beginning of the message. – chikuba Apr 30 '12 at 00:56
  • and yeah that would be the ideal solution but since I have no idea how to solve that (just been following tutorials to get to where i am) i was hoping that someone maybe had the same issue and solved it :) – chikuba Apr 30 '12 at 00:58
  • This might actually be a bug in AppVerifier: [this SO question](http://stackoverflow.com/questions/9854243/appverifier-reports-invalid-handle-code-c0000008-when-closing-valid-handle) has similar problems and though there is no answer yet, the "Exception Analysis" section states that a NULL value for handle is treated as invalid. OTOH [the CreateFile documentation](http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx) states that it is OK to pass a NULL value for the handle. As a workaround, treat your bailout log file as your regular one while testing under AppVer. – Attila Apr 30 '12 at 11:40
  • but how do you configure the pantheios so that it doesnt write to any file? my backend is the console and have no idea why it even tries to write to a file. also, it seems to be an exception in the stl-lib aswell, as you can see. possible that's where the createFileA is located, not too sure – chikuba Apr 30 '12 at 21:10
  • I'm not familar with pantheios enough to answer that question. If you have the source, you can trace it back where that CreateFile is used. Otherwise contact the authors/ask another question on SO :) – Attila Apr 30 '12 at 22:56
  • yeah :p this question is pretty much it. written down everything i know here. might just have to contact someone – chikuba Apr 30 '12 at 23:54