Re: Throwing a simple exception

From: Computer Whizz (old486whizz_at_hotmail.com)
Date: 10/24/04


Date: Sun, 24 Oct 2004 11:07:05 +0100


"David Lindauer" <camille@bluegrass.net> wrote in message
news:417ACB1B.F20CCAA9@bluegrass.net...
>
>
> JKop wrote:
>
>> Let's say you've a very simple function, that, if it fails, should throw
>> an
>> exception. The thing is though, it's not important enough to go and
>> actually
>> define an "exception class" for, so... is there any general exception
>> class
>> defined in the Standard Library that I could use in such circumstances,
>> maybe something like:
>>
>
> for example:
>
> #include <stdexcept>
>
> using namespace std ;
>
> void myfunc(bool bad_things_happen)
> {
> if (bad_things_happen)
> throw runtime_error("my message here") ; // use a runtime_error
> since
> you can't associate a
>
> //message
> with the standard 'exception' class
> }
> int main(int argc, char **argv)
> {
> try {
> myfunc(true) ;
> } catch (runtime_error &aa) { // note you could catch 'exception' here
> if you
> want to catch all the
> // exceptions in stdexcept
> cout << aa.what() ; // prints your message
> }
> }

Wow - I knew about the exception messages - but didn't know you could catch
them...
Can you catch <exception> errors too? Or is this just for <stdexcept> ?

-- 
=========
Comp Whizz
=========
(The C++ beginner) 


Relevant Pages

  • Re: Threading and Serial port issue
    ... "fails" is pretty useless information. ... If it generates an exception, ... I then sit in a loop waiting for data to arrive. ... private void SetupBoard_Click ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Strange error when app starts
    ... installed correctly via the installer ... machines and until recently they all worked perfectly. ... updated the application to a new version one of the machines fails ... unhandled exception when the application starts. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Coding inside the debugger
    ... but why isn't the test written so that the reason it fails is ... If something fails in tests like these, ... public void testCreateWithDefaultthrows Exception { ... Ghostworld world = worldWithClass; ...
    (comp.object)
  • Re: update multiple rows continue past exceptions
    ... that fails causes the entire transaction to fail. ... don't have the exception. ... UPDATE MYTAB SET request = REPLACE(request, '$tpsToModify', ... Indeks er oprettet. ...
    (comp.databases.oracle.server)
  • Re: How to tell if source video contains audio?
    ... >> in a try/catch and this is the Message in the exception. ... > with no audio and, if this fails to, then the file can not ... > WME because that's what WME tries to do and, if it fails, ...
    (microsoft.public.windowsmedia.sdk)