You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2020/08/06 17:33:00 UTC

[jira] [Commented] (CALCITE-4151) Forbid usages of Exception#printStackTrace variants

    [ https://issues.apache.org/jira/browse/CALCITE-4151?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17172563#comment-17172563 ] 

Julian Hyde commented on CALCITE-4151:
--------------------------------------

This makes sense.

However, let's not create the impression that printing a stack trace to a logger is always OK. Usually it's not. Most Calcite code is library code and should (wrap and) re-throw.

> Forbid usages of Exception#printStackTrace variants
> ---------------------------------------------------
>
>                 Key: CALCITE-4151
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4151
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: Stamatis Zampetakis
>            Assignee: Stamatis Zampetakis
>            Priority: Minor
>
> Exception#printStackTrace is a convenient way to print stack trace related information to standard error and potentially other output streams. However, most of the time (if not always) is a bad idea to do so. There are many articles online, outlining why it is not a good idea to use these APIs. 
> Briefly instead of calling Exception#printStackTrace someone should: 
> * Log it using a logger and the appropriate level (e.g [LOG.error|http://www.slf4j.org/apidocs/org/slf4j/Logger.html#error(java.lang.String,java.lang.Throwable)], [LOG.info|http://www.slf4j.org/apidocs/org/slf4j/Logger.html#info(java.lang.String,java.lang.Throwable)], etc.)
> * Re-throw the exception wrapping it if necessary 
> * Let the exception propagate and let other callers act as they see fit
> In this issue we aim to replace existing calls with appropriate alternatives (as mentioned above) and add the API to the list of forbidden signatures.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)