Skip to content

Files

Latest commit

 

History

History
41 lines (30 loc) · 654 Bytes

PrintStackTrace.md

File metadata and controls

41 lines (30 loc) · 654 Bytes

Pattern: Printing stacktrace of an exception

Issue: -

Description

Instead of simply printing a stacktrace a better logging solution should be used.

Example of incorrect code:

fun foo() {
    Thread.dumpStack()
}

fun bar() {
    try {
        // ...
    } catch (e: IOException) {
        e.printStackTrace()
    }
}

Example of correct code:

val LOGGER = Logger.getLogger()

fun bar() {
    try {
        // ...
    } catch (e: IOException) {
        LOGGER.info(e)
    }
}

Further Reading