How can I throw an Exception when a properties file contains a duplicate property? Here is an example demonstrating this situation:
# Properties-file
directory=D:\\media\\D-Downloads\\Errorfile\\TEST_A
directory=D:\\media\\D-Downloads\\Errorfile\\TEST_B
#directory=D:\\media\\D-Downloads\\Errorfile\\TEST_C
I suppose you are reading the file with something like
Properties.load()
. It sets the parameter internally usingput(key, value)
. You can override that method to get the desired behaviour like e.g.EDIT:
Integrating this into the OP's code:
By the way, why would you want to catch the exception? I'd not continue a program if its configuration is corrupt (maybe catching at top-level to log the event). But exception-handling is a different topic...
(EDIT: my original code samles didn't compile, I corrected them)