what different between them.

Hi! I got 3 question:
1. what different between exit(0) and exit(1)? when are time suitable to use them.
2. what this following mean for and what the different?:
    void fnA();throw();
    void fnA();throw(char*);
3. what is namespace? when we need to use namespace? why we need to use namespace?

Thanks for help!
From: Sally
sally1980Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

n_fortynineCommented:
1. Usually when you terminate a program/process usually it's desirable for other processes to know the minimal reason *why* the program was terminated. So usually exit (0) denotes an "successful" exit, and exit (1) means exit with "error" (there could be many more). These values are conventional, i.e. they've meanings designated to them by the coder.

2. throw( ) does not take any parameter. This is what most standard exception classes would do. throw(char *) would take a char array as argument, usually that would be the exception message, e.g. throw("Cannot allocate memory"). You would have to write appropriate code to handle this if you're writing your own exception handlings.

for example
class myException {
    string errMess;
   public:
    myException(string mess) : errMess(mess) {}
    const string getMess() { return errMess; }
   //...
};

3. Namespaces are usually in large project development. To give an example, say you coded a function void foo(void), and so did Mr. X. Now the compiler will get confused not knowing which one to use when they're put together in the project.
So by doing
namespace myStuff {
   void foo() {...}
}

namespace MrXStuff {
   void foo() {...}
}

You can distinguish them by calling myStuff::foo() or MrXStuff::foo() or do
using myStuff::foo;
foo(); //this is your foo
using MrXStuff::foo;
foo(); //Mr.X foo.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rstaveleyCommented:
Ref 1:

The exit code from exit(N) is equivalent to the return value from main, when the return value is used.You can test the exit code in a batch file or script.

e.g.
   test.bat
   --------8<--------
   myprog.exe
   if errorlevel 1 goto badexit
   echo That was OK
   goto exit
   :badex
   echo That didn't go well
   :exit
   --------8<--------

Note that the DOS batch file "if errorlevel 1" test tests if the exit code was 1 or above. If you want to test multiple exit codes you need to start by testing the high numbered ones first.

e.g.

  test.sh
  --------8<--------
  #!/bin/sh

   ./myprog
   EXITCODE=$?
   if test $EXITCODE = 1; then
     echo Uh-oh we encountered error 1
   else
      echo The error code was $EXITCODE
   fi
   --------8<--------

Exit code 0 is conventionally used to indicate success and any other number (max 255) indicates an error.

Ref 2:

> void fnA();throw();
> void fnA();throw(char*);

A member function declared with throw() should throw no exceptions. It is some kind of a guarantee. You see it used extensively in the standard library. The semicolon before throw() shouldn't be there in the declaration. Where you see throw(char*), you have a function which may throw a char*.

e.g.

   myprog.cpp:
   --------8<--------
   #include <iostream>
   struct foo {
   public:
       void doitbadly() throw(const char*);
   };

   void foo::doitbadly() throw(const char*)
   {
        throw "Oo-err lummee, missus!";
   }

   int main()
   {
      try {
           foo x;
           x.doitbadly();
      }
      catch (const char *message) {
           std::cerr << "Exception thrown: Message was: " << message << '\n';
           exit(1);
      }
      std::cout << "No exceptions thrown\n";
      return 0;
   }
   --------8<--------
0
tinchosCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: n_fortynine {http:#9676239}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.