PrepAway - Latest Free Exam Questions & Answers

How would you handle the exception, so that value either contains the session’s ID, or returns an empty

The following utility method requires the handling of an exception: How would you handle the
exception, so that value either contains the session’s ID, or returns an empty string?

PrepAway - Latest Free Exam Questions & Answers

A.
You add a try/catch block (in bold) around the value assignment:
try
{
value = session.getSessionId();
}
catch (DfException dfe)
{
DfLogger.debug(this,dfe.getStackTraceAsString(),null,null);
}

B.
You add a throws clause (in bold) to the method signature:
public String getMySessionId(IDfSession session) throws DfException
{

}

C.
Exception handling is not required becausesession.isConnected() ensures a session is
present, and
session.getSessionId() only throws an exception if the session is not present.

D.
You add a throws clause (in bold) to the method signature AND add a try/catch block (in
bold) around the value assignment that throws a new DfException():
public String getMySessionId(IDfSession session) throws DfException
{
String value = “”;
try
{
value = session.getSessionId();
}
catch (DfException dfe)
{
DfLogger.debug(this,dfe.getStackTraceAsString(), null,null);
}
return value;
}


Leave a Reply