From: RaG on
Hi,
I converted code from vc6 to vc9, on vc6 environment the below
statement is working fine

fprintf (stderr, "Failed FormatMessage - MessageIndex = <%d>.\n", 0);

but when I run this on vc9(visual studio 2008)
an exception is thrown,How to handle the exception is the issue.
The exception condition will occur definitely but handling that is
what I need.In vc6 same code is working fine.

Any one please Help it is very urgent to solve the exception.

From: Giovanni Dicanio on
"RaG" <b.raghavender(a)gmail.com> ha scritto nel messaggio
news:1b201de8-2654-46c8-9bd1-b6f850644880(a)f29g2000yqa.googlegroups.com...

> fprintf (stderr, "Failed FormatMessage - MessageIndex = <%d>.\n", 0);
>
> but when I run this on vc9(visual studio 2008)
> an exception is thrown,How to handle the exception is the issue.
> The exception condition will occur definitely but handling that is
> what I need.In vc6 same code is working fine.

What is the exception thrown?

The general way of catching exceptions in C++ is by using try/catch, i.e.

try {
...
code
...
}
catch( const std::exception & e ) {
std::cerr << "*** ERROR: " << e.what() << std::endl;
}


Giovanni


From: RaG on
On Feb 23, 2:36 pm, "Giovanni Dicanio"
<giovanniDOTdica...(a)REMOVEMEgmail.com> wrote:
> "RaG" <b.raghaven...(a)gmail.com> ha scritto nel messaggionews:1b201de8-2654-46c8-9bd1-b6f850644880(a)f29g2000yqa.googlegroups.com...
>
> > fprintf (stderr, "Failed FormatMessage - MessageIndex = <%d>.\n", 0);
>
> > but when I run this on vc9(visual studio 2008)
> > an exception is thrown,How to handle the exception is the issue.
> > The exception condition will occur definitely but handling that is
> > what I need.In vc6 same code is working fine.
>
> What is the exception thrown?
>
> The general way of catching exceptions in C++ is by using try/catch, i.e.
>
>  try {
>    ...
>    code
>    ...
>  }
>  catch( const std::exception & e ) {
>     std::cerr << "*** ERROR: " << e.what() << std::endl;
>  }
>
> Giovanni

exception handling already there, but still the below exception is
comming
First-chance exception at 0x7c91b21a in unittest.exe: 0xC0000005:
Access violation writing location 0x00000010.
From: Goran on
On Feb 23, 10:25 am, RaG <b.raghaven...(a)gmail.com> wrote:
> Hi,
> I converted code from vc6 to vc9, on vc6 environment the below
> statement is working fine
>
> fprintf (stderr, "Failed FormatMessage - MessageIndex = <%d>.\n", 0);
>
> but when I run this on vc9(visual studio 2008)
> an exception is thrown,How to handle the exception is the issue.

No, not really. If you "handle" the exception, your code still doesn't
work ;-). I think it's better to fix the problem at the origin.

I just tried, this works:

int _tmain(int argc, _TCHAR* argv[])
{
fprintf(stderr, "Failed FormatMessage - MessageIndex = <%d>.\n", 0);
return 0;
}

You should provide here a working example of what's not working ;-).

Alternatively, you can step into fprintf and look at what it does, or,
in Debug->Exceptions, Check "Win 32 Exceptions" under thrown and debug
with that. That will stop in debugger when exception is thrown. Look
at stack trace and at variable values for "unusual" things.

Goran.
From: Ismo Salonen on
RaG wrote:
> On Feb 23, 2:36 pm, "Giovanni Dicanio"
> <giovanniDOTdica...(a)REMOVEMEgmail.com> wrote:
>> "RaG" <b.raghaven...(a)gmail.com> ha scritto nel messaggionews:1b201de8-2654-46c8-9bd1-b6f850644880(a)f29g2000yqa.googlegroups.com...
>>
>>> fprintf (stderr, "Failed FormatMessage - MessageIndex = <%d>.\n", 0);
>>> but when I run this on vc9(visual studio 2008)
>>> an exception is thrown,How to handle the exception is the issue.
>>> The exception condition will occur definitely but handling that is
>>> what I need.In vc6 same code is working fine.
>> What is the exception thrown?
>>
>> The general way of catching exceptions in C++ is by using try/catch, i.e.
>>
>> try {
>> ...
>> code
>> ...
>> }
>> catch( const std::exception & e ) {
>> std::cerr << "*** ERROR: " << e.what() << std::endl;
>> }
>>
>> Giovanni
>
> exception handling already there, but still the below exception is
> comming
> First-chance exception at 0x7c91b21a in unittest.exe: 0xC0000005:
> Access violation writing location 0x00000010.

My crystall ball tells me that stderr is not open. Is the program a
console application ? Normal windows applications need to freopen stderr
themselves.

ismo