Throwing and Catching Exceptions

Viewed 17061

Hey StackOverflow Community,

Regarding throwing exceptions. Generally, when do I throw and exception, and when do I catch it?

Let' say I come across these situation where I have to quit because of some problem that occurred and I can't recover from it. Do I throw or do I catch?

I do this right now:

    try {
       // some code
    }
    catch (IOException e) {
       logger.info("Failed to do something, and cannot continue" + e.getMessage(), e);
       e.printStackTrace();
       throw e;
    }

Is this the right thing to do? Would it be more appropriate if I just threw the exception? Sorry, I'm a newbie at exceptions :)

6 Answers
Related