Solved

"raise" and "exception" ...

Posted on 2003-10-27
4
202 Views
Last Modified: 2010-04-02
To C++ Experts,

   How is "raise" to do with "exceptions" ? can I have an example ?
 thanks.

 
0
Comment
Question by:meow00
  • 3
4 Comments
 
LVL 19

Assisted Solution

by:Dexstar
Dexstar earned 50 total points
ID: 9630552
meow00:

> How is "raise" to do with "exceptions" ? can I have an example ?

In C++, you don't "raise" exceptions.  You "throw" them.

     void SomeFunction()
     {
          try
          {
               int i = 5;

               if ( i < 5 )
                    throw i;
          }
          catch( int n )
          {
               cout << "Caught int Exception: " << n << endl;
          }
     }

Does that make it more clear?

Hope that helps,
Dex*
0
 
LVL 1

Author Comment

by:meow00
ID: 9630610
I see .... so what does raise do :
In the book (C++ in a nutshell): "The raise function sends a signal to the running program." But I don't really understand what it means ......
thanks.
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 50 total points
ID: 9630633
meow00:

> I see .... so what does raise do :
> In the book (C++ in a nutshell): "The raise function sends a signal to the
> running program." But I don't really understand what it means ......

I've been programming in C/C++ since 1992 or so, and I've never used that function.  So, I looked it up and found this:
     http://www.qnx.com/developer/docs/qnx_6.1_docs/neutrino/lib_ref/r/raise.html

Which will give you a sample of its usage.
But, in general, that is the "old sk00l" way of doing it.  With C++, you have exceptions, and so the signal()/raise() functions are pretty much obsolete.

Dex*
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9634621
meow00:

I'm glad that you accept my answers, but I'm sure it isn't necessary to split the points between my 2 answers, since they all go to the same person.  You should save that for when you want to split the points between two different people.  :)

Dex*
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

733 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