2

I am writing an application where a human user / a service will write excel files to a particular directory. Now the program will always listen to directory changes , will parse this excel and will try to convert this into a xml file based on a schema. Now I have few custom exceptions like

  • InvalidFileException
  • InvalidFormatException
  • MissingDataException

etc.

I want to know is it a good idea to drive logic based on the exceptions? Means if it throws InvalidFile exception I want to execute some logic .. I am using WatchService from java 7

avinandan012
  • 143
  • 1
  • 13
  • 1
    My understanding is that that is exactly what exceptions are for: to capture a defined but unwanted result and try to act in consequence. Otherwise you would not try to catch exceptions at all. – cnluzon Jun 23 '15 at 08:43
  • 1
    Not an good idea - see http://stackoverflow.com/questions/5378005/when-is-it-ok-to-use-exception-handling-for-business-logic – Scary Wombat Jun 23 '15 at 08:50
  • finally written logic in catch blocks. To avoid any type of memory usage issue every time launching a new jvm instance from cmd prompt from a batch file – avinandan012 Jul 06 '15 at 09:17

1 Answers1

-1

That is why they are there. If you need it then use it and there is nothing wrong with it.

https://docs.oracle.com/javase/tutorial/essential/exceptions/advantages.html

AbuHayA
  • 30
  • 5
  • @Downvoter For this kind of file handling adding business logic to the catch block is completly okay. – AbuHayA Jun 23 '15 at 09:42