I'm just afraid because just like in ConnectException, there are lot of scenarios that could trigger it. And if I have to display a really specific error message to the user, then I must also check the message of the exception. Not just the name of the Exception only.
There are not many scenarios: "a timeout has occurred on a socket read or accept". You should know if you're doing a socket read or accept. So you know exactly what happened and where. I am calling e. If you're allowed to throw exception without a message, so is Android. Exception messages are intended for the developer, not for the user. Android code is Java code. You should catch the exception, and display an appropriate error message to the user yourself. JB Nizet: Yes. That is why I also have to know the cause of the exception via its message.
My plan is to do something like this: [if e. If I won't be able to determine the main cause of the exception, then I won't also be able to display a specific error message for the user. The type of the exception and the location where it's thrown are supposed to be sufficient to display a meaningful error message.
You shouldn't rely on the message of the exception. JB Nizet gives the example of my suggestion. IgorGanapolsky I didn't know that they are separate entities. Just learned about it today. So there are some errors that Java didn't provide a message? Yes, the message is only optional. But I think it's not a very good software design to let the message null, because the message helps the user to get more detailed information about the error. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. See "3. Regarding the original problem, I'd suggest using e. For some exceptions the message doesn't make sense without knowing the exception type. An example I've encountered is where e. Which would you prefer to see in your logs? In my case it was returning the wrong Exception with a null message, because I wrapped the result of the method call in an Optional variable:.
The code seems fine syntax wise and e. Now either there is issue with your logger or you might be looking at the wrong line in logger file.
It completely depends upon which logger are you using? Have you overridden the methods of looger. However it is for sure that e. You can also try that by printing e. 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. Asked 10 years, 1 month ago. Active 7 months ago. Viewed k times. Improve this question. Kevin 7 7 silver badges 21 21 bronze badges. Revathi Revathi 1, 8 8 gold badges 19 19 silver badges 24 24 bronze badges.
Because there is no message set. I would say, you should write your own exception class and set the message — hop. Add a comment. Active Oldest Votes. Throwing java. Improve this answer.
Stephen C Stephen C k 90 90 gold badges silver badges bronze badges. Indeed a null error message in a NullPointerException is beyond my understanding: I mean it is trying to help a programmer to correct a mistake by creating a second mistake of the same type? It is very, very old behavior. We can't guarantee quick solutions - Experts Exchange isn't a help desk. We're a community of IT professionals committed to sharing knowledge. Our experts volunteer their time to help other people in the technology industry learn and succeed.
Plans and Pricing. Contact Us. Certified Expert Program. Credly Partnership. Udemy Partnership. Privacy Policy.
0コメント