Results 1 to 4 of 4
  1. #1
    xtheunknown0 is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Catching exceptions where there's no caller

    I'm using Slick2D, where I assume that init, update and render methods are for you to override. Given the way Slick2D works and since the program is a game, I don't actually call these methods, but they throw SlickExceptions. Is there a better way to catch these exceptions (which currently aren't being caught) than to put try-catch blocks in each of these methods?

  2. #2
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Re: Catching exceptions where there's no caller

    I think the bigger question is why are they being thrown? What's the error message?

    But no, unless you implement your own version of BasicGame, you'd have to catch it in the method or in whatever method the exception is thrown from. Pretty sure this is intended though.
    Last edited by AndrewM16921; 09-28-2013 at 05:39 AM.

  3. #3
    xtheunknown0 is offline Member
    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Default Re: Catching exceptions where there's no caller

    Quote Originally Posted by AndrewM16921 View Post
    I think the bigger question is why are they being thrown? What's the error message?
    These methods (given the template code provided to me) actually call methods with the same name in the World class. The versions in the World class throw exceptions if objects like Image aren't created successfully. So what I did while waiting for a reply was to write methods that either return null or the reference to a created object back to the caller. That way, these smaller methods do the try-catching, removing the potential for the callers to throw SlickExceptions, so once I'm done, none of the methods in Game should throw SlickExceptions.

    I hope this is a good idea.

  4. #4
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Re: Catching exceptions where there's no caller

    Give it a try. If you run into further problems, it may help to post some of your code here.

Similar Threads

  1. Having trouble catching exceptions
    By fatabass in forum New To Java
    Replies: 2
    Last Post: 03-17-2012, 05:02 AM
  2. Catching Exceptions (quick question)
    By Danieldcc in forum New To Java
    Replies: 3
    Last Post: 02-20-2012, 12:40 AM
  3. catching exceptions (hierarchy)
    By kailash in forum Java Servlet
    Replies: 2
    Last Post: 02-10-2011, 07:43 AM
  4. Help with Catching Exceptions
    By javaman1 in forum New To Java
    Replies: 4
    Last Post: 09-11-2010, 03:06 AM
  5. catching uncaught exceptions using Spring / WebApp
    By taille50 in forum Web Frameworks
    Replies: 1
    Last Post: 10-18-2009, 02:14 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
  •