Program Flow for a Location 
Tracing the flow of a program is a common practice: entering, exiting, throwing, assertion.
entering() – outputs a default message, indicating that it enters a source block. It has severity INFO.
This method is always in pair with exiting().
Entering() Methods |
Description |
|---|---|
entering() |
Enters a source block. |
entering(String subloc) |
Specifies the method name in subloc. |
entering(Object[] args) |
A general source block with arguments: "Entering method with <args>". |
entering(String subloc, Object[] args) |
The same as the previous one, but with a specific method name. |
exiting() – outputs a default message, indicating that it leaves a source block. It has severity INFO.
This method is always in pair with entering().
Exiting() Methods |
Description |
|---|---|
exiting() |
Exits a source block. As the method name (subloc) is specified in 'entering', it is no longer necessary to provide a subloc as argument. The result is presented in the sample code below. |
exiting(Object res) |
A general source block with result"Exiting method with <res>": . |
exiting(String subloc, Object res) |
The same as the previous one, but with a specific method name. |
To reiterate, refer to the sample code with method announce(Object o):
Syntax
public void announce(Object o) {
String method = "announce(java.lang.Object)";
loc.entering(method);
try {
} catch (Exception e) {
}
loc.exiting();
}The potential output, assuming the simplest case with ConsoleLog and default TraceFormatter, is:
May 3, 2007 6:54:18 PM com.sap.fooPackage.Node.announce [main] Info: Method is entered May 3, 2007 6:54:18 PM com.sap.fooPackage.Node.announce [main] Info: Method is entered |
throwing() – a message, indicating that the source block is about to throw an exception. It has severity WARHING.
Throwing() Methods |
Description |
|---|---|
throwing(Throwable exc) |
Throws the exception exc. |
throwing(String subloc, Throwable exc) |
The same as the previous one, but with a specific method name. |
assertion() – to test a condition and output an error message, when the evaluation is false. It has severity ERROR.
Assertion() Methods |
Description |
|---|---|
assertion(Boolean assertion, String desc) |
Evaluates the assertion. If false, prints desc with the default message: "Assertion failed: <desc>", where <desc> is the assertion test itself. For example, 5 > 3. |
assertion (String subloc,Boolean assertion, String desc |
The same as the previous one, but with a specific method name. |
To reiterate, refer to the sample code with method announce(Object o):
Syntax
public void announce(Object o) {
String method = "announce(java.lang.Object)";
loc.assertion(method, 5 < 3,"Inadequate comparison“);
try {
}
catch (Exception e) {
loc.throwing(method, e);
}
}The potential output, assuming the simplest case with ConsoleLog and default TraceFormatter, is:
May 3, 2007 6:54:18 PM com.sap.fooPackage.Node.announce [main] Error: Assertion failed: Inadequate comparison May 3, 2007 6:54:18 PM com.sap.fooPackage.Node.announce [main] Warning: Throwing java.io.FileNotFoundException: C:\Not_Exist\zzzzz.log (The system cannot find the path specified) |