Results 1 to 2 of 2

Thread: Why use Try?

  1. #1
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Rep Power

    Default Why use Try?

    Why do people use the try method? What is the point? Is it so that if there is an error it knows how to handle it? How would you know when there would be an error? Also what happens when you do try but don't handle the exception, and how should you handle your exceptions?

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Tucson, AZ
    Rep Power

    Default Re: Why use Try?

    First of all, the word "method" has a very specific meaning in Java. And 'try' is not a method.

    The basic idea is that when a method is declared to throw a checked exception, the programmer must deal with it in some way. This reduces runtime bugs. Here's a brief overview: Try Statements in Java - For Dummies

    In general, you should only catch exceptions if you can do something about them. Otherwise, declare your own method to throw them. And never catch and exception and then completely ignore it. At least print the stack trace.
    Get in the habit of using standard Java naming conventions!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts