Closed azmfaridee closed 12 years ago
The goal is every function in mothur will have a try/catch
in it. The catch passes an error message to the logger to let us know where the error occurred and the type of error.
try{
}catch(exception& e) {
m->errorOut(e, "ClassName", "functionName");
exit(1);
}
The only signal mothur captures currently is Control C. Normally if the user pressed Control C the program would be terminated, but we want to use it to quit a command. At regular key places in your code you should check for this and if it has been pressed cleanup memory, remove output files and quit the command. If you are in a subclass, return up to the command level cleaning up as you go. The mothurOut
class has a listener to check for the signal, so you just need to ask mothurOut
if its been pressed. Here's an example from cooccurrencecommand.cpp
line 188
.
if (m->control_pressed) {
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
delete input;
out.close();
m->mothurRemove(outputFileName);
return 0;
}
The mothurOut
class handles the logging. You should never output using bout
. The key logging functions are:
void mothurOut(string); //writes to cout and the logfile
void mothurOutEndLine(); //writes to cout and the logfile
void mothurOut(string, ofstream&); //writes to the ofstream, cout and the logfile
void mothurOutEndLine(ofstream&); //writes to the ofstream, cout and the logfile
void mothurOutJustToLog(string);
The mothurOut
class also has many useful functions that should be used whenever possible to reduce code duplication. The most frequently used function include: openInputFile
, openOutputFile
, setGroups
, getGroups
, currentBinLabels
, mothurConvert
, mothurRemove
and gobble
.
Parent Issue: #4
Find the command practices in mothur, they are such as but not limited to: