It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Monica Shiralkar wrote:If I should not catch exception in every layer and use throws, then how should I throw a custom exception for my application?
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Stephan van Hulst wrote:Logging exceptions AND throwing new exceptions doesn't make sense. .
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Daniel Demesmaecker wrote:
Stephan van Hulst wrote:Logging exceptions AND throwing new exceptions doesn't make sense. .
Why not? In the customexception she trows she can warn the user with a simple message(althought she could do that without trowing a new one), while the logfile contains the stacktrace for the person that maintains the program...
Ivan Jozsef Balazs wrote:
Daniel Demesmaecker wrote:
Stephan van Hulst wrote:Logging exceptions AND throwing new exceptions doesn't make sense. .
Why not? In the customexception she trows she can warn the user with a simple message(althought she could do that without trowing a new one), while the logfile contains the stacktrace for the person that maintains the program...
Well, if you do this in every layer, then the situation can become confuse. It is however (usually) possible to create an exception with another as a cause. But to cope with a chaining coming from several layers might become tedious. An exception should be caught and coped with where it is meaningful. For example if a string is given to some method which in turn gives it further to other methods and at the end a File is made out of it and finally some IO operation is tried against the File, but fails, the resulting exception should arguably percolated to the place, where the string was originally provided, and should be coped with there.
A Happy New Year btw!
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Stephan van Hulst wrote:That's fine, but then why not log the exception in the same place you display the message?
I think every exception should have one place where they're handled. If you log an exception and then rethrow it, there's a big chance it's going to be logged twice, needlessly blowing up your logging file.
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Why are you putting your customException in a try block?
All things are lawful, but not all things are profitable.
Monica Shiralkar wrote:Not for logging custom message but for showing custom message.E.g for cases of showing a custom message on the web UI?
Paul Clapham wrote:Since you're doing the same thing in both catch blocks you can simplify that some more: