Changes

From Genome Analysis Wiki
Jump to navigationJump to search
1,684 bytes added ,  09:43, 17 September 2010
no edit summary
Line 1: Line 1:  
=== Review Sept 17th ===
 
=== Review Sept 17th ===
 +
==== Review Discussion Topics ====
 +
===== Return Statuses =====
 +
Currently anytime you do anything on a SAM/BAM file, you have to check the status for failure:
 +
<source lang="cpp">
 +
  SamFile samIn;
 +
  if(!samIn.OpenForRead(argv[1]))
 +
  {
 +
      fprintf(stderr, "%s\n", samIn.GetStatusMessage());
 +
      return(samIn.GetStatus());
 +
  }
    +
  // Read the sam header.
 +
  SamFileHeader samHeader;
 +
  if(!samIn.ReadHeader(samHeader))
 +
  {
 +
      fprintf(stderr, "%s\n", samIn.GetStatusMessage());
 +
      return(samIn.GetStatus());
 +
  }
 +
</source>
 +
A previous recommendation was to "Add an option by class that says whether or not to abort on failure. (or even an option on each method)"
 +
 +
I am proposing modifying the classes to throw exceptions on failures.  It would then be up to the user to catch them if they want to handle them or to let them exit the program (which would print out the error message)
 +
<source lang="cpp">
 +
  SamFile samIn;
 +
  samIn.OpenForRead(argv[1]);
 +
 +
  // Read the sam header.
 +
  SamFileHeader samHeader;
 +
  samIn.ReadHeader(samHeader);
 +
 +
  // Open the output file for writing.
 +
  SamFile samOut;
 +
  try
 +
  {
 +
      samOut.OpenForWrite(argv[2]);
 +
  }
 +
  catch(GenomeException e)
 +
  {
 +
      std::cout << "Caught an Exception" << e.what() << std::endl;
 +
  }
 +
</source>
 +
For caught exceptions, you would see the following and processing would continue:
 +
<pre>
 +
Caught Exception:
 +
FAIL_IO: Failed to Open testFiles/unknown for writing
 +
</pre>
 +
 +
For an uncaught exception, you would see the following and processing would be stopped:
 +
<pre>
 +
terminate called after throwing an instance of 'GenomeException'
 +
  what(): 
 +
FAIL_IO: Failed to Open testFiles/unknown for reading
 +
Aborted
 +
</pre>
    
=== Review June 7th ===
 
=== Review June 7th ===

Navigation menu