Results 1 to 3 of 3
  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    233
    Rep Power
    3

    Default Exception name for wrong return type?

    I am developing a try-catch statement but want to know the name of the exception thrown when a method returns with the wrong data type.

    e.g. if I had this method:

    Java Code:
    public static int returnInt(){
    
         String name = "bobby";
         return name;
    }

    What exception would be throw if that was ran?




    Or would it just not compile?

  2. #2
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    233
    Rep Power
    3

    Default Re: Exception name for wrong return type?

    Actually, just tried it, it won't compile. Sorry

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Exception name for wrong return type?

    The compiler should catch this case. The only way in java that I can think of to force a wrong type error is with casting, in which case you get a ClassCastException.

Similar Threads

  1. Return to an input that was wrong!!
    By daemonlies in forum New To Java
    Replies: 2
    Last Post: 03-30-2012, 05:06 AM
  2. What Should be my Return type....
    By Anagha in forum New To Java
    Replies: 6
    Last Post: 04-14-2011, 11:29 AM
  3. method return statement is wrong
    By ftrengnr in forum New To Java
    Replies: 1
    Last Post: 10-19-2010, 04:15 AM
  4. Replies: 1
    Last Post: 03-08-2008, 06:41 PM
  5. The return type
    By Marcus in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 06:28 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
  •