Sponsored Content
Full Discussion: exit in cpp
Top Forums Programming exit in cpp Post 302345224 by Michael Safyan on Tuesday 18th of August 2009 05:32:52 PM
Old 08-18-2009
Throw an exception.

What you want to do is throw an exception.

Code:
// Special exception to throw
class exit_exception : public runtime_error
{
  public:
     exit_exception() : runtime_error("Termination"), _code(0) {}
     exit_exception(int code) : runtime_error("Termination"), _code(code){}
     virtual ~exit_exception(){}
     int getStatusCode()const{ return _code; }
  private:
      int _code;
};

Code:
// Main function
int main(int argc, char* argv[])
{
    int retcode = 0;
    try {
          // program content...
    }catch(const exit_exception& quit){
         retcode = quit.getStatusCode();
    }
    return retcode;
}

Code:
// ...
throw(exit_exception(0)); // Instead of exit(0)
// ...

 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Hi Modem Problem And cpp

Hi am very new to unix.I got installed linux mandrake and the first problem is whith the modem i don't know why but it does not work. i config it on /dev/modem and some time it says "the modem is bussy" and some time it says: "Modem ready" but the modem did'n switch on Ok the other question... (3 Replies)
Discussion started by: user666
3 Replies

2. Programming

cpp in unix

sir i am trying to compile and execute cpp file in unix the command cpp <filename > is not working do you suggest any other command? thanking you (5 Replies)
Discussion started by: sandhyapidugu
5 Replies

3. UNIX for Dummies Questions & Answers

Where can I find a list of exit codes? (Exit code 64)

I'm receiving an exit code 64 in our batch scheduler (BMC product control-m) executing a PERL script on UX-HP. Can you tell me where I can find a list of exit codes and their meaning. I'm assuming the exit code is from the Unix operating system not PERL. (3 Replies)
Discussion started by: jkuchar747
3 Replies

4. Programming

gcccommand found how to do with cpp

gcc help iam using kubuntu os (www.ubuntu.com) in that i dont find gcc but cpp command is there how to compile code with that & how to use gij for java in ubuntu (1 Reply)
Discussion started by: seshumohan
1 Replies

5. Shell Programming and Scripting

If file = .cpp then print?

I'm trying to develop a script that makes it so only .cpp programs can print. I'm doing it for my computer programming class because everyone keeps printing the executable instead of the source code and it's wasting a lot of paper. How can I accomplish this? Thanks for the help. :D (5 Replies)
Discussion started by: Irish_Cereal
5 Replies

6. Shell Programming and Scripting

reading a cpp file

I need to find all the methods in a cpp file ... using shell script Pls guide me regarding the grep criteria for searching methods I mean what are the patterns to be grepped in *.cpp which match methods Hope i have made myself clear Thanks and Regards -- Ultimatix (2 Replies)
Discussion started by: ultimatix
2 Replies

7. Shell Programming and Scripting

CPP to PERL

Hi all, can we convert a cpp program to perl scripting ? (4 Replies)
Discussion started by: Shell_Learner
4 Replies

8. Programming

.h or .cpp

I have the code below and cannot decide if to put it in a .h file or in a .cpp file #ifndef VERBOSE_H #define VERBOSE_H #include "sstring.h" enum Verbose { none = 0, low = 1, medium = 2, high = 3, diag = 4 }; bool GetVerbose(String& S, Verbose& V) { S.ToUpper(); if (S ==... (3 Replies)
Discussion started by: kristinu
3 Replies
Test::Exit(3pm) 					User Contributed Perl Documentation					   Test::Exit(3pm)

NAME
Test::Exit - Test that some code calls exit() without terminating testing VERSION
version 0.03 SYNOPSIS
use Test::More tests => 4; use Test::Exit; exits_ok { exit 1; } "exiting exits" never_exits_ok { print "Hi!"; } "not exiting doesn't exit" exits_zero { exit 0; } "exited with success" exits_nonzero { exit 42; } "exited with failure" DESCRIPTION
Test::Exit provides some simple tools for testing that code does or does not call "exit()", while stopping code that does exit at the point of the "exit()". Currently it does so by means of exceptions, so it will not function properly if the code under test calls "exit()" inside of an "eval" block or string. The only criterion tested is that the supplied code does or does not call "exit()". If the code throws an exception, the exception will be propagated and you will have to call it yourself. "die()"ing is not exiting for the purpose of these tests. exits_ok Tests that the supplied code calls "exit()" at some point. exits_nonzero Tests that the supplied code calls "exit()" with a nonzero value. exits_zero Tests that the supplied code calls "exit()" with a zero (successful) value. never_exits_ok Tests that the supplied code completes without calling "exit()". AUTHOR
Andrew Rodland <andrew@hbslabs.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2009 by HBS Labs, LLC.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.10.1 2009-12-04 Test::Exit(3pm)
All times are GMT -4. The time now is 09:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy