is there a tool to remove throw list declarations?

  • Thread starter Christian Schuhegger
  • Start date
C

Christian Schuhegger

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,
 
W

Wouter Lievens

Christian Schuhegger said:
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.
 
J

JKop

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
 
C

Christian Schuhegger

JKop said:
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.
 
J

JKop

Christian Schuhegger posted:
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
 
T

tom_usenet

Christian Schuhegger posted:


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
 
J

JKop

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
 
C

Christian Schuhegger

Christian said:
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 --
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top