Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

For starters, I had a tool (App.exe) that was written in C++6, one of the most important aspects was the return codes which indicated where the tool failed.

This was really simple to do, I made my MAIN return int and then when I get to failure points I just do "return 1;" or "return 2;", etc... and this would return the correct value.

 

Now I am re-writing the same tool in C# (as a Console Application called App.exe) but the Return Codes are not working.

So far no matter what I try it always returns a value of 0x0 no matter where it fails, I have already tried a few different ways (as seen below) and nothing seems to works.

 

try
{
// DO THE WORK
}
catch
{
//Environment.ExitCode = RET_UNKNOWNSTATIONTYPE;
//Environment.Exit(RET_UNKNOWNSTATIONTYPE);
//return RET_UNKNOWNSTATIONTYPE;
}

 

So from the above code you can see I have already tried 3 different approaches, setting the ExitCode, Exiting with an ExitCode, and simply Returning the value (as I used to do with C++6 and worked fine)

However, in all 3 cases I get the following (from the debug window)

The program '[1704] App.exe' has exited with code 0 (0x0).

 

No matter what I try it never returns with a return code (note that RET_UNKNOWNSTATIONTYPE = 0x00000001;)

Any clues, help, or hints would be greatly appreciated.

Thanks,

  • *Experts*
Posted

I wouldn't trust the output window for the ExitCode. If you test your EXE with a batch job (to test the exit code) or test it otherwise, using the first two examples should work fine. I couldn't get the "return NN;" to work even when Main was declared as returning int.

 

I've used the "Environment.ExitCode = NN;" syntax and it works fine.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...