Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 8
Now that you know something about StackTraceElement, that class's methods, and what stack-trace data looks like, you probably want to experiment with that class. But first,
you need to understand a few more concepts. After presenting those concepts, I give you a chance to work with StackTraceElement.
The exceptions class hierarchy includes a rich assortment of exception classes. When you need an exception class, you should
first search that hierarchy for an appropriate class. If you cannot find an appropriate class or if you need a class resembling
an existing class, you extend that hierarchy with a new class. Where does the new class fit within the overall class hierarchy?
You must ask yourself if the class describes a checked exception or an unchecked exception. Assuming the answer is checked
exception, the class appears within the Exception subhierarchy -- but not within that subhierarchy's RuntimeException portion. However, if the answer is unchecked exception, the class appears within the RuntimeException subhierarchy. Because you shouldn't handle unchecked exceptions that describe JVM failures, ignore the Error subhierarchy. To clarify this discussion, I present the following two examples:
Throwable layer and record the integer-based response code in a private field of each class. You avoid duplicating response code fields
by introducing a generic superclass that declares that field and extendes that class with POP3 and SMTP exception subclasses.
The following code fragment demonstrates:class EmailException extends Exception
{
private int responseCode;
EmailMessage (int responseCode, String message)
{
// Call Exception(String message), which calls Throwable(String message).
super (message);
this.responseCode = responseCode;
}
int getResponseCode ()
{
return responseCode;
}
}
class POP3Exception extends EmailException
{
}
class SMTPException extends EmailException
{
}
EmailException extends Exception because sometimes SMTP- and POP3-related exceptions arise from reasons other than flawed code -- perhaps the SMTP or POP3
program stops running during a communication session. As a result, POP3Exception and SMTPException identify different checked exceptions. (I'll discuss email, POP3, and SMTP in a future article.)