CH11 - Exceptions and Localization Flashcards

(17 cards)

1
Q

Unchecked Exception

A

An unchecked exception is any exception that does not need to be declared or handled by the application code it is thrown.

Unchecked exceptions are often referred to as runtime exceptions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Error

A

Error means something went so horribly wrong that your program should not attempt to recover from it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Throwable

A

Throwable is that it’s the parent class of all exceptions, including the Error class.

While you can handle Throwable and Error exceptions, it is not recommended you do so in your app code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Checked Exception

A

Subclass of Exception but not subclass of RuntimeException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Unchecked Exception

A

Subclass of RuntimeException

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Overriding method with Exception

A

An overridden method may not declare any new or broader checked exceptions that the method it inherits.

An overridden method in a subclass is allowed to declare fewer exceptions than the superclass or interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

try-with-resources

A

Only classes that implement the AutoCloseable interface can be used in a try-with-resources statement.

Inheriting AutoClosable requires implementing a compatible close() method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Closable

A

Closeable extends AutoClosable they are both supported in try-with-resources statements.

Difference Closeable’s close() method declares IOException, while AutoCloseable’s close() method declares Exception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Scope of Try-With-Resources

A

The resources created in the try clause are in scope only within the try block.

This is anoter way to remember that the implicit finally runs before any catch/finally blocks that you code yourself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

📦 NumberFormat — What It Does

A

-Formats numbers as plain numbers, currency, or percentages

-Parses strings back into numbers

-Adapts to locales (e.g., decimal separator in US vs Germany)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Common Subclasses of NumberFormat

A

NumberFormat
DecimalFormat
Currency
Percent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Basic Number Formatting

A

NumberFormat nf = NumberFormat.getInstance();

System.out.println(nf.format(1234567.89)); // e.g., “1,234,567.89” (in US)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Locale-Specific Formatting

A

NumberFormat nfFR = NumberFormat.getInstance(Locale.FRANCE);
System.out.println(nfFR.format(1234567.89));

// e.g., “1234567,89”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

📌 Rules for Custom Text:

A

Wrap any literal text in single quotes ‘…’.

To write a single quote character, use ‘’ (double single quote).

DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“hh:mm a ‘o’‘clock’”);
// Output: 03:25 PM o’clock

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Unchecked exceptions can be thrown in any method,
Is it coorect claim?

A

YES

In Java, unchecked exceptions (also called runtime exceptions) are:

Subclasses of RuntimeException

Not required to be declared in a method’s throws clause

Can be thrown in any method, at any time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Multi-catch block

A

In multi-catch block, all caught exception types must be disjoint - i.e. no subtype - supertype relationships.
Otherwise, one of the exception types would never be reached.

In a multi-catch block, all exception types must be unrelated(disjoint) - no subtype/supertype relationship - to avoid unreachable code.

17
Q

try-with-resources

A

It must be either:
-Declared inside the try block
- Effectively final (nor reassigned after initialized)