Solved

"raise" and "exception" ...

Posted on 2003-10-27
4
197 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now