Logs&Exceptions Flashcards

1
Q

Zapis pridani loggeru, pkg

A

private static final Logger logger = Logger.getLogger(MyClass.getName());
java.util.logging

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

Nastaveni loggeru do file - nazev souboru + obsah (XML, warning)

A

logging.properties
.level=WARNING
handler=java.util.logger.FileHandler
java.util.logger.FileHandler.formatter=XMLFormatter
-//- .pattern=filenamePattern-%g.log
-//- .limit=1000
-//- .count=1 (rotace filu)

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

Nastaveni loggeru pro package “pkg” do konzole - nazev souboru + obsah (ne XML, info)

A

logging.properties
pkg.level=INFO
handler=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.formatter=SimpleFormatter

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

varianty log metody,

A

info(“message”)
log(Level.INFO, “message”)
log(Level.INFO, “message”, causeEx)
log(Level.INFO, “message {0}”, messageParam)

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

Parent vsech exceptions
Checked vs unchecked exceptions

A

Throwable
Checked - chytaji se a deklaruji povinne (nemusi byt v catch, pokud je finally)
Unchecked - potomci RuntimeException, nemusi se chytat a deklarovat

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

Co muze byt v catch 5

A

e.printStackTrace()
throw new Exception(e)
Throwable ex = e.getCause()
Throwable[] exs = e.getSupressed()
return; - finally se provede, ale metoda nepokracuje

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

Try-with-parameters - priklad zapisu
+ kdo tam smi byt
+ co se stane, pokud “finally” vyhodi vyjimku

A

try (BR br = new BufferedReader; PW pw = new PrintWriter()) { … } catch …

AutoCloseable (maji metodu close())
je potlacena, lze ji ziskat z exception.getSuppressed()

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

Typy handleru (5), typy formatteru (2)

A

Console
File
Memory
Socket
Stream

SimpleFormatter, XmlFormatter

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

Logger metody: nastaveni urovne - je uroven alespon ? - vstup, vystup z metody - vyjimka

A

setLevel(Level.SEVERE)
isLoggable(Level.SEVERE)
entering, exiting
throwing

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

metody pro precise log (class a metoda) a resource bundle log

A

logp
logrb

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

syntaxe tvorby vlastni vyjimky

A

public class MyException extends Exception() {
// konstruktory, ktere volaji super
}

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

Assertions:
jak je zapnout
syntax s a bez error message
co se stane, pokud failne

A

-ea (enable assertions) jako parametr pro jvm, defaultne jsou vyple
assert boolVar;
assert boolVar: errorMsg;
program skonci

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

JVM parametr pro verbose NullPointerException

A

-XX:+ShowCodeDetailsInExceptionMessages

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

Return v catch
Return ve finally

A

catch: provede se finally a pak metoda skonci
finally: metoda skonci. Pokud byl return v catch, muj ho prepise

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