Does throwing an exception in a windows service crash the service?
i.e. it will have to be restarted manually
Note: I am throwing the exception from within the catch clause.
The rule of thumb I tend to follow is to throw an exception as soon as I can't continue or recover the desired code execution path, then allow that exception to propagate back up the stack to a place that understands how to handle that exception. Don't catch an exception if all you're going to do is re-throw.
Exceptions should be thrown when the contract between a method and its caller cannot be fulfilled.
Any code can throw an exception: your code, code from a package written by someone else such as the packages that come with the Java platform, or the Java runtime environment. Regardless of what throws the exception, it's always thrown with the throw statement.
Exceptions should be used for exceptional situations outside of the normal logic of a program. In the example program an out of range value is likely to be fairly common and should be dealt with using normal if-else type logic.
Not strictly so -- it'd only cause problems if the exception is unhandled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With