is there a tool to remove throw list declarations?

Discussion in 'C++' started by Christian Schuhegger, Jul 23, 2004.

  1. hi,

    we are working on a c++ project which has a lot of thow list
    specifications which in the end causes a lot of problems. now i would
    like to remove them from the project. because the project has a size of
    300000+ lines of code it is not so easy to do all of that manually.

    therefore my question: is there a tool that you run on your sources and
    which just converts the throw declarations into a comment? a tool that
    only comments the declarations would be ideal, because as documentation
    the declarations will still be useful.

    thanks,
    --
    Christian Schuhegger
    http://www.el-chef.de/
     
    Christian Schuhegger, Jul 23, 2004
    #1
    1. Advertising

  2. "Christian Schuhegger" <> schreef in bericht
    news:cdqan4$q8r$...
    > hi,
    >
    > we are working on a c++ project which has a lot of thow list
    > specifications which in the end causes a lot of problems. now i would
    > like to remove them from the project. because the project has a size of
    > 300000+ lines of code it is not so easy to do all of that manually.
    >
    > therefore my question: is there a tool that you run on your sources and
    > which just converts the throw declarations into a comment? a tool that
    > only comments the declarations would be ideal, because as documentation
    > the declarations will still be useful.
    >
    > thanks,


    I don't think it's a lot of work to write that yourself, in case you fail to
    find such a tool.
     
    Wouter Lievens, Jul 23, 2004
    #2
    1. Advertising

  3. Christian Schuhegger

    JKop Guest

    Christian Schuhegger posted:

    > hi,
    >
    > we are working on a c++ project which has a lot of thow

    list
    > specifications which in the end causes a lot of problems.

    now i would
    > like to remove them from the project. because the project

    has a size of
    > 300000+ lines of code it is not so easy to do all of that

    manually.
    >
    > therefore my question: is there a tool that you run on

    your sources and
    > which just converts the throw declarations into a

    comment? a tool that
    > only comments the declarations would be ideal, because as

    documentation
    > the declarations will still be useful.
    >
    > thanks,



    Open an editor. Tools->Replace

    Replace "throw"
    with "//throw"


    -JKop
     
    JKop, Jul 23, 2004
    #3
  4. JKop wrote:
    > Open an editor. Tools->Replace
    >
    > Replace "throw"
    > with "//throw"

    i agree that the problem looks simple, but it is not that simple :)

    what do you do if there is a:
    void AnyClass::anyMethod() throw () {
    then you comment the { aswell which you don't want to do!

    it is also not correct to use a regex to match for (something similar
    to:) "throw (.*)", because you could have in your code body something like:
    throw (new MyException());

    i mean, obviously a task like commenting the throw declarations can be
    automised, but it is not as simple as you might think. therefore, before
    inventing the wheel again i would prefer to use a tool that somebody
    else probably already has written.
    --
    Christian Schuhegger
    http://www.el-chef.de/
     
    Christian Schuhegger, Jul 23, 2004
    #4
  5. Christian Schuhegger

    JKop Guest

    Christian Schuhegger posted:

    > JKop wrote:
    >> Open an editor. Tools->Replace
    >>
    >> Replace "throw"
    >> with "//throw"

    > i agree that the problem looks simple, but it is not that simple :)
    >
    > what do you do if there is a:
    > void AnyClass::anyMethod() throw () {
    > then you comment the { aswell which you don't want to do!
    >
    > it is also not correct to use a regex to match for (something similar
    > to:) "throw (.*)", because you could have in your code body something
    > like:
    > throw (new MyException());
    >
    > i mean, obviously a task like commenting the throw declarations can be
    > automised, but it is not as simple as you might think. therefore,
    > before inventing the wheel again i would prefer to use a tool that
    > somebody else probably already has written.


    Replace "throw()"
    with "/* throw() */"

    replace "throw ()"
    with "/* throw () */"

    Replace "throw ( )"
    with "/* throw ( ) */"

    template<class T>
    void DummyThrow(T) {}

    #define throw DummyThrow


    -JKop
     
    JKop, Jul 23, 2004
    #5
  6. Christian Schuhegger

    JKop Guest

    Make that:

    template<class T>
    void DummyThrow(const T&) {}


    -JKop
     
    JKop, Jul 23, 2004
    #6
  7. Christian Schuhegger

    tom_usenet Guest

    On Fri, 23 Jul 2004 12:50:51 GMT, JKop <> wrote:

    >Christian Schuhegger posted:
    >
    >> JKop wrote:
    >>> Open an editor. Tools->Replace
    >>>
    >>> Replace "throw"
    >>> with "//throw"

    >> i agree that the problem looks simple, but it is not that simple :)
    >>
    >> what do you do if there is a:
    >> void AnyClass::anyMethod() throw () {
    >> then you comment the { aswell which you don't want to do!
    >>
    >> it is also not correct to use a regex to match for (something similar
    >> to:) "throw (.*)", because you could have in your code body something
    >> like:
    >> throw (new MyException());
    >>
    >> i mean, obviously a task like commenting the throw declarations can be
    >> automised, but it is not as simple as you might think. therefore,
    >> before inventing the wheel again i would prefer to use a tool that
    >> somebody else probably already has written.

    >
    >Replace "throw()"
    >with "/* throw() */"
    >
    >replace "throw ()"
    >with "/* throw () */"
    >
    >Replace "throw ( )"
    >with "/* throw ( ) */"
    >
    >template<class T>
    >void DummyThrow(T) {}
    >
    >#define throw DummyThrow


    What about legitimate uses of throw? E.g.

    throw std::runtime_error("Something went wrong!");

    That will become:

    DummyThrow std::runtime_error("Something went wrong!");

    which is obviously a syntax error.

    Tom
     
    tom_usenet, Jul 23, 2004
    #7
  8. Christian Schuhegger

    JKop Guest

    First here's some sample code:


    #include <stdexcept>

    class AnyClass {
    public:

    void AnyMethod() throw();

    };

    void AnyClass::AnyMethod() throw ()
    {
    throw;
    }


    int main()
    {
    AnyClass monkey;

    try
    {

    throw std::runtime_error("Something went wrong!");

    throw AnyClass();

    monkey.AnyMethod();

    }
    catch(...)
    {
    AnyClass ape;
    }
    }


    I'm trying to get the following to work:


    class DummyThrow
    {
    public:
    template<class T>
    DummyThrow& operator=(const T&) const { return *this; }
    };

    #define throw() /* z */

    #define throw(a) /* z */

    #define throw DummyThrow() =

    #define try if(1)

    #define catch(...) if(0)


    But I can't get it to compile.


    -JKop
     
    JKop, Jul 23, 2004
    #8
  9. Christian Schuhegger wrote:
    > therefore my question: is there a tool that you run on your sources and
    > which just converts the throw declarations into a comment? a tool that
    > only comments the declarations would be ideal, because as documentation
    > the declarations will still be useful.


    the following perl script seems to do the job fine:

    -- snip start --
    $filename = $ARGV[0];
    open(IN,$filename);

    $text = "";
    while($line = <IN>) {
    $text .= $line;
    }
    close(IN);

    $text =~ s/(throw[ \t\r\n]*\([ \t\r\n]*[A-Za-z_]+:):[A-Za-z_]+)*[
    \t\r\n]*(,[ \t\r\n]*[A-Za-z_]+:):[A-Za-z_]+)*[ \t\r\n]*)*\))/\/\* $1 \*\//g;
    print $text;
    -- snip end --

    --
    Christian Schuhegger
    http://www.el-chef.de/
     
    Christian Schuhegger, Jul 24, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kerri
    Replies:
    2
    Views:
    13,091
    Kevin Spencer
    Oct 27, 2003
  2. Replies:
    15
    Views:
    7,707
    Roedy Green
    Sep 8, 2005
  3. H.
    Replies:
    7
    Views:
    5,203
    Greg R. Broderick
    Apr 5, 2007
  4. Emanuele D'Arrigo

    To throw or to throw not?

    Emanuele D'Arrigo, Nov 14, 2008, in forum: Python
    Replies:
    6
    Views:
    341
    Emanuele D'Arrigo
    Nov 15, 2008
  5. Francis Hwang
    Replies:
    1
    Views:
    106
    Yukihiro Matsumoto
    Nov 20, 2003
Loading...

Share This Page