Ameba Ownd

アプリで簡単、無料ホームページ作成

threadercoclo1981's Ownd

Why not printstacktrace

2022.01.12 23:15




















Early Access Courses. Assessments New. Free Trial New. For Business. For Educators. Become an Affiliate. Terms of Service. Business Terms of Service. Careers Hiring. When i analysed my code running sonar, it reflected printing stack trace as violation of java coding standard. As an alternative to stack trace, I tried:. Error handling can be tricky in any environment, java included. I haven't used sonar, but I can comment on general good practices for java error handling.


Because of this you can't really control where this output goes. The better thing to do is to use a logging framework logback, slf4j, java. And generally you'll want to catch the exception and if it's unexpected behavior, log it and either throw a new exception probably specific to your application or do whatever you have to do to continue operating gracefully. I presume from the title you were using e. This does not "clear the exception", so I'm not sure exactly what your issue really is on that point.


In java "clear the exception" doesn't make any sense at all in this context. Much better to write such detail to a log file for later diagnostics, rather than put it out in front of a user though that could depend on how the program actually runs.


Your run-time environment may have something to say about use of standard output. Must stack traces will show this after an initial stack dump denoted by "Caused by: Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Save Article. Improve Article.


Like Article. Output: java. Output: Error: java. Next 3 Different ways to print Exception messages in Java. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments.