Results 1 to 9 of 9
  1. #1
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default How many no. of exceptions can be thrown????

    Is there any upper bound on the number of exceptions that can be thrown by a piece of code..:cool:
    The Quieter you become the more you are able to hear !

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    An interesting follow up would be: and what exception is thrown when that limit is exceeded?

    If you mean the number of "catch" clauses, there is a limit o the size of a class once it is compiled into byte code. But, in practice, readability and common sense would seem to impose a much lower limit.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    The question that that question brings to mind for me is "why?", "Why do you want (or think you need) to know this?"

    If you have any method that comes anywhere close to throwing the "max allowed" that method is doing far too much and needs to be refactored. And the same goes for any one block that needs to catch that many.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Stephen Douglas View Post
    Is there any upper bound on the number of exceptions that can be thrown by a piece of code..:cool:
    That is a silly question; you might as well have asked about the maximum number of assignments in a piece of code. The maximum size supported for a method is 64KB; statements in a try block and statements in a catch block take up bytes; do your math.

    kind regards,

    Jos

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

    Default

    There are several physical limitations on the JVM as already mentioned. Maximum method size, which you should never never ever come close to. Maximum size of a class, which you should also never never ever come close to. These are fixed.

    There are also limitations to the number of classes loaded, which is your PermGen space. This can be expanded, but again there's a limit (not sure what it is, but there's always a limit). And finally good old heap. I expect you could blow that if you built loads of exceptions wrapped in exceptions etc.

    But it's a pretty meaningless question...as you can see, there's nothing special about exceptions in that lot.

  6. #6
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    My friend confronted this as an objective question in an online exam he appeared..... I was myself baffled ! However the options were :

    One
    Two
    Three
    Four


    thanx for the reponses...

    The maximum size supported for a method is 64KB; statements in a try block and statements in a catch block take up bytes; do your math.
    There are several physical limitations on the JVM
    i myself never wondered if there was an upper bound to the size of class and methods... Can you people provide me the links where i can learn more about such an information in detail. thnx
    Last edited by Stephen Douglas; 04-30-2010 at 05:29 PM.
    The Quieter you become the more you are able to hear !

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Stephen Douglas View Post
    i myself never wondered if there was an upper bound to the size of class and methods... Can you people provide me the links where i can learn more about such an information in detail. thnx
    It's all in the Java Virtual Machine Specification. Especially pay close attention to chapter 4; it describes the class file format.

  8. #8
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Quote Originally Posted by Stephen Douglas View Post
    My friend confronted this as an objective question in an online exam he appeared..... I was myself baffled ! However the options were :

    One
    Two
    Three
    Four

    More than likely, the exam showed a particular piece of code and asked about the exceptions that code could possibly throw.

    -Gary-

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by gcalvin View Post
    More than likely, the exam showed a particular piece of code and asked about the exceptions that code could possibly throw.
    ... or the question asked about the different types of Exceptions (checked, unchecked, errors etc.)

    kind regards,

    Jos

Similar Threads

  1. Exceptions & More
    By besweeet in forum New To Java
    Replies: 12
    Last Post: 04-29-2010, 10:06 PM
  2. connect to derby thrown SQLException
    By newbiejava in forum New To Java
    Replies: 5
    Last Post: 01-20-2010, 06:25 PM
  3. Replies: 0
    Last Post: 06-08-2009, 10:59 PM
  4. Need Help With Exceptions
    By maggie_2 in forum New To Java
    Replies: 5
    Last Post: 12-15-2008, 08:12 PM
  5. Which exception is thrown.....
    By money123 in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 04:41 PM

Posting Permissions

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