Solved

"raise" and "exception" ...

Posted on 2003-10-27
4
198 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ - Convert a wString to char * 9 517
Socket Programming (Unix) 8 119
thread-safe code in c++ 2 86
How to gracefully close the c++ 11 thread? 3 83
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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.

867 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

22 Experts available now in Live!

Get 1:1 Help Now