?
Solved

"raise" and "exception" ...

Posted on 2003-10-27
4
Medium Priority
?
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 19

Assisted Solution

by:Dexstar
Dexstar earned 200 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 200 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

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

765 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