Java Reference
In-Depth Information
Example 16-14. Log14Demo2—catching and logging
public
public class
class
Log14Demo2
Log14Demo2
{
public
public static
static
void
void
main
(
String
[]
args
) {
System
.
setProperty
(
"java.util.logging.config.file"
,
"logging/logging.properties"
);
Logger logger
=
Logger
.
getLogger
(
"com.darwinsys"
);
try
try
{
Object o
=
new
new
Object
();
logger
.
info
(
"I created an object: "
+
o
);
iif
(
o
!=
null
null
) {
// bogus, just to show logging
throw
throw new
new
IllegalArgumentException
(
"Just testing"
);
}
}
catch
catch
(
Exception t
) {
// All-in-one call:
logger
.
log
(
Level
.
SEVERE
,
"Caught Exception"
,
t
);
// Alternate: Long form, more control.
// LogRecord msg = new LogRecord(Level.SEVERE, "Caught exception");
// msg.setThrown(t);
// logger.log(msg);
}
}
}
Finding Network Interfaces
Problem
You wish to find out about the computer's networking arrangements.
Solution
Use the
NetworkInterface
class.
Discussion
Every computer on a network has one or more “network interfaces.” On typical desktop ma-
chines, a network interface represents a network card or network port or some software net-