Commit 684a395b authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[trac755] Remove unnecessary try-catch

The ofstream closes automatically when destroyed.
parent d22ff004
......@@ -264,52 +264,46 @@ writeHeaderFile(const string& file, const vector<string>& ns_components,
// Open the output file for writing
ofstream hfile(header_file.fullName().c_str());
try {
if (hfile.fail()) {
throw MessageException(MSG_OPENOUT, header_file.fullName(),
strerror(errno));
}
if (hfile.fail()) {
throw MessageException(MSG_OPENOUT, header_file.fullName(),
strerror(errno));
}
// Write the header preamble. If there is an error, we'll pick it up
// after the last write.
hfile <<
"// File created from " << message_file.fullName() << " on " <<
currentTime() << "\n" <<
"\n" <<
"#ifndef " << sentinel_text << "\n" <<
"#define " << sentinel_text << "\n" <<
"\n" <<
"#include <log/message_types.h>\n" <<
"\n";
// Write the message identifiers, bounded by a namespace declaration
writeOpeningNamespace(hfile, ns_components);
vector<string> idents = sortedIdentifiers(dictionary);
for (vector<string>::const_iterator j = idents.begin();
j != idents.end(); ++j) {
hfile << "extern const isc::log::MessageID " << *j << ";\n";
}
hfile << "\n";
// Write the header preamble. If there is an error, we'll pick it up
// after the last write.
hfile <<
"// File created from " << message_file.fullName() << " on " <<
currentTime() << "\n" <<
"\n" <<
"#ifndef " << sentinel_text << "\n" <<
"#define " << sentinel_text << "\n" <<
"\n" <<
"#include <log/message_types.h>\n" <<
"\n";
// Write the message identifiers, bounded by a namespace declaration
writeOpeningNamespace(hfile, ns_components);
vector<string> idents = sortedIdentifiers(dictionary);
for (vector<string>::const_iterator j = idents.begin();
j != idents.end(); ++j) {
hfile << "extern const isc::log::MessageID " << *j << ";\n";
}
hfile << "\n";
writeClosingNamespace(hfile, ns_components);
writeClosingNamespace(hfile, ns_components);
// ... and finally the postamble
hfile << "#endif // " << sentinel_text << "\n";
// ... and finally the postamble
hfile << "#endif // " << sentinel_text << "\n";
// Report errors (if any) and exit
if (hfile.fail()) {
throw MessageException(MSG_WRITERR, header_file.fullName(),
strerror(errno));
}
hfile.close();
}
catch (MessageException&) {
hfile.close();
throw;
// Report errors (if any) and exit
if (hfile.fail()) {
throw MessageException(MSG_WRITERR, header_file.fullName(),
strerror(errno));
}
hfile.close();
}
......@@ -357,76 +351,71 @@ writeProgramFile(const string& file, const vector<string>& ns_components,
// Open the output file for writing
ofstream ccfile(program_file.fullName().c_str());
try {
if (ccfile.fail()) {
throw MessageException(MSG_OPENOUT, program_file.fullName(),
strerror(errno));
}
// Write the preamble. If there is an error, we'll pick it up after
// the last write.
if (ccfile.fail()) {
throw MessageException(MSG_OPENOUT, program_file.fullName(),
strerror(errno));
}
ccfile <<
"// File created from " << message_file.fullName() << " on " <<
currentTime() << "\n" <<
"\n" <<
"#include <cstddef>\n" <<
"#include <log/message_types.h>\n" <<
"#include <log/message_initializer.h>\n" <<
"\n";
// Write the preamble. If there is an error, we'll pick it up after
// the last write.
// Declare the message symbols themselves.
ccfile <<
"// File created from " << message_file.fullName() << " on " <<
currentTime() << "\n" <<
"\n" <<
"#include <cstddef>\n" <<
"#include <log/message_types.h>\n" <<
"#include <log/message_initializer.h>\n" <<
"\n";
writeOpeningNamespace(ccfile, ns_components);
// Declare the message symbols themselves.
vector<string> idents = sortedIdentifiers(dictionary);
for (vector<string>::const_iterator j = idents.begin();
j != idents.end(); ++j) {
ccfile << "extern const isc::log::MessageID " << *j <<
" = \"" << *j << "\";\n";
}
ccfile << "\n";
writeOpeningNamespace(ccfile, ns_components);
writeClosingNamespace(ccfile, ns_components);
vector<string> idents = sortedIdentifiers(dictionary);
for (vector<string>::const_iterator j = idents.begin();
j != idents.end(); ++j) {
ccfile << "extern const isc::log::MessageID " << *j <<
" = \"" << *j << "\";\n";
}
ccfile << "\n";
// Now the code for the message initialization.
writeClosingNamespace(ccfile, ns_components);
ccfile <<
"namespace {\n" <<
"\n" <<
"const char* values[] = {\n";
// Now the code for the message initialization.
// Output the identifiers and the associated text.
idents = sortedIdentifiers(dictionary);
for (vector<string>::const_iterator i = idents.begin();
i != idents.end(); ++i) {
ccfile << " \"" << *i << "\", \"" <<
quoteString(dictionary.getText(*i)) << "\",\n";
}
ccfile <<
"namespace {\n" <<
"\n" <<
"const char* values[] = {\n";
// Output the identifiers and the associated text.
idents = sortedIdentifiers(dictionary);
for (vector<string>::const_iterator i = idents.begin();
i != idents.end(); ++i) {
ccfile << " \"" << *i << "\", \"" <<
quoteString(dictionary.getText(*i)) << "\",\n";
}
// ... and the postamble
ccfile <<
" NULL\n" <<
"};\n" <<
"\n" <<
"const isc::log::MessageInitializer initializer(values);\n" <<
"\n" <<
"} // Anonymous namespace\n" <<
"\n";
// Report errors (if any) and exit
if (ccfile.fail()) {
throw MessageException(MSG_WRITERR, program_file.fullName(),
strerror(errno));
}
ccfile.close();
}
catch (MessageException&) {
ccfile.close();
throw;
// ... and the postamble
ccfile <<
" NULL\n" <<
"};\n" <<
"\n" <<
"const isc::log::MessageInitializer initializer(values);\n" <<
"\n" <<
"} // Anonymous namespace\n" <<
"\n";
// Report errors (if any) and exit
if (ccfile.fail()) {
throw MessageException(MSG_WRITERR, program_file.fullName(),
strerror(errno));
}
ccfile.close();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment