Originally posted by miguel lisboa:
are those 'this' really needed at all?
No, but it's common style to include them to be 100% clear. Where they're
necessary is in a standard setter method:
Some people prefer to prefix all member variables with _ or m; others prefix their arguments with _ or the (theName); still others rely on the
IDE to color the variables (Eclipse) based on the scope.
I used to prefer simply writing clear code and disambiguating the few cases that weren't obvious (or using "this" in setters). The more and more I have to deal with other people's code, the more I am thankful to see the "this."
can one catch some of those exceptions with, lets say, a warning msg dialog?
Absolutely! And as Layne pointed out, it will make your code much more reusable and maintainable. If you throw meaningful exceptions in the worker code (a data-access object for example), then your UI code can catch it and handle it (show an error dialog).
When you want to reuse that same DAO in a command-line or automated tool, you can catch it and print an error -- and exit(1) if severe -- or log a message. If you put the code to display an error dialog in the DAO itself, you're pegged to a GUI app.