Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
Like Tree1Likes

Thread: Question about Exception handling

  1. #21
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Quote Originally Posted by bigsonny View Post
    This is really not practical.
    Yes it is practical. Otherwise how is the compiler supposed to know where that class you are trying to use is? I imagine your comeback will be "It is in the Java API so it should always know where the class is" Okay, what about third part libs? There are a vast number of Java packages on the net free to use in your program. All the Apache POI stuff for dealing with Word and Excel files for example. How is the compiler supposed to know where those classes are unless you tell it where.
    This means that the code could end up with a bunch of import statements...
    I don't mean to be rude but BOOHOO! So you have to add a bunch of import statements at the start of your class. It won't kill you.

  2. #22
    yellowledbet is offline Senior Member
    Join Date
    Feb 2011
    Location
    Georgia, USA
    Posts
    122
    Rep Power
    0

    Default

    1. The import statement shows java where to find the class.
    2. A super class has no knowledge of its sub classes.
    3. A sub class can be created in any package (i.e. there is no requirement that it will be located in same package as super class)

  3. #23
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Quote Originally Posted by bigsonny View Post
    Could I just import java.lang.*;
    What did I just tell you about importing java.lang classes? Obviously it doesn't work because those classes are not in the lang package.

  4. #24
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Exceptions are pretty tricky when you are new. I actually have a post I made here 7 months ago asking what the point of exceptions are. When I was new they seemed strange.

    Some things that may help:
    Learn the difference between checked and unchecked exceptions, find out which should be caught and which are signaling an error on your part.

    Recognize that exceptions are classes just like anything else(String, Scanner,etc), and they work the same way.

    Exceptions should be used for exceptional situations. Errors that can occur, but it's an exceptional occurrence.

  5. #25
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by Junky View Post
    P.S. Catching runtime exceptions is generally frowned upon. If a runtime exception is thrown then it is an indication that there is a logic error in your code which should be corrected not just swallowed up with a catch statement.
    It depends.
    A lot of frameworks (thinking Spring and Hibernate specifically at the moment) use RuntimeExceptions as the standard, so it is quite legitimate to catch a HibernateException if you are potentially expecting one. I don't necessarily agree with this, but it's quite popular so you work with it.

  6. #26
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    Quote Originally Posted by Junky View Post
    You know how to write a main method?
    Java Code:
    public static void main(String[] args)
    Well guess what?
    Java Code:
    public static void main(String[] foo)
    public static void main(String[] bar)
    public static void main(String[] stuff)
    public static void main(String[] anExtremelyLongAndPointlessNameSoWhyDidIChooseIt)
    All the above are valid and will compile.
    My favorite is
    Java Code:
    public static void main(String... aaarrrrgggGGHHHHHHH)
    db

  7. #27
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Quote Originally Posted by Tolls View Post
    It depends.
    I did say "generally" ;)

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Exception Handling
    By link6790 in forum New To Java
    Replies: 16
    Last Post: 05-19-2011, 07:57 PM
  2. Exception Handling
    By eLancaster in forum New To Java
    Replies: 4
    Last Post: 02-20-2011, 01:00 AM
  3. Handling Exception - elementary question
    By kracer in forum New To Java
    Replies: 2
    Last Post: 05-07-2010, 12:47 AM
  4. Exception Handling help
    By MZA in forum New To Java
    Replies: 3
    Last Post: 02-10-2010, 10:23 AM
  5. Exception Handling...
    By focus_nitin in forum New To Java
    Replies: 1
    Last Post: 02-16-2008, 04:13 AM

Posting Permissions

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