Add logging andexception handling to your code
== Logging ==
Add logging to your code- This means thatyour program will generate log file and generate log events as executes The log events will detail your program execution. Theoutput of my log Alc is posted online. Your file docs not need to match mine exactly, but the exceptions should match up. (It might be good idea to match exactly for what it $ Worth, since it helps you find subtle errors.)
There are two partstologgings
(1) adding infrastructure for logging
(2) making your data flow codcuse that infrastructure
== adding infrastructure for logging ==
Checkout the class Logger in the file logging.h. You need to add methods associated with that class-
== making your data flow code use that infrastructure ==
You will log an event by calling with a "char *" named
For example, my routine
char msg[128];
sprintf(msg. to execute" SourceName())
sprintf(msg. '%st donc executing SourceName())
You can see exactly where Iput my logging code in the Ale "logger".
== Exception handling ==
There are two parts to the exception handling
(1) adding infrastructure for exception handling
(2) making your data flow codcuse that infrastructure adding infrastructure for exception handling ==
There is ;really only one thing to do herer add constructor
You will need to implement constructor for DataFlowException that stores the exception in the "msg" data member
If the constructor gets type "Shrinker" and error "bad sizes" then it should make msg bc equal tor (Shrinker): bad sizes" For what itis worth, my constructor also logs event- making your data flow code use that infrastructure ==
There are many spots where you can add exception handling in your data flow code.
My driver program only tests three of them
Here is my code that checks for and throws exceptions
if input->GetWidth() 1= input2->GetWidth())
char msg[1024];
sprintf(msg. "%s widths must match %d. %d". SinkName() input->GetWidth(),
DataFlowException c(SinkName(),msg);
throw c;
IMPORTANT: the final "Stress teSt" project at the end of the term can include programs that should cause exceptions. So addingas many error checks as possible now good- Hint itis convenient to add the following pure virtual functions
conSt char *SourcewSourceNatne() 0:
conSt char 0;
conSt char *FilternFulterName() =0:
they make coding faster in Several spots (Note my code abovo useS SinkNamc)
(also, definer
conSt char *FilternSourceNatnc() return FilterName();}
conSt char *FilternStnkNatne() return FilterName();};

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <filter.h>
#include <logging.h>
#include <iostream>

void filter::Update()
char msg[128];
if (ptr1->link != NULL)
sprintf(msg,"%s:about to update input1 ",SourceName());
sprintf(msg,"%s:done update input1 ",SourceName());
if ((ptr2 != NULL) && (ptr2->link != NULL))
sprintf(msg,"%s:about to update input2 ",SourceName());
sprintf(msg,"%s:done update input2 ",SourceName());

const char * filter::SourceName()
return FilterName();

const char * filter::SinkName()
return FilterName();

void Shrinker::Execute()
char msg[14] = "Input is NULL";
if (ptr1 != NULL)
img.ResetSize(ptr1->GetWidth()/2, ptr1->GetHeight()/2);
for (int w=0; w < img.GetWidth(); w++)
for (int h=0; h < img.GetHeight(); h++)
unsigned char *p = ptr1->GetPixel(2*w, 2*h);
img.SetPixel(w, h, p);
DataFlowException e(FilterName(),msg);
throw e;

const char * Shrinker::FilterName()
return "Shrinker";

void LRConcat::Execute()
char msg[15] = "Input1 is NULL";
if (ptr1 != NULL)
int width = ptr1->GetWidth();
int height = ptr1->GetHeight...
$30.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Computer Science - Other Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats