Thread: [HELP] Someone explain this please?

Results 1 to 6 of 6
  1. #1 [HELP] Someone explain this please? 
    Registered Member

    Join Date
    Oct 2009
    Posts
    67
    Thanks given
    0
    Thanks received
    1
    Rep Power
    163
    The Catch or Specify Requirement:
    Valid Java programming language code must honor the Catch or Specify Requirement. This means that code that might throw certain exceptions must be enclosed by either of the following:

    A try statement that catches the exception. The try must provide a handler for the exception
    A method that specifies that it can throw the exception. The method must provide a throws clause that lists the exception

    Can someone show me the block of code which explains the try statement which catches the exception.
    Also the method that specifies that it can throw the exception, this would be much appreciated
    нσтуυтє'ѕ 566

    Proud Tester/Admin For нσтуυтє
    Reply With Quote  
     

  2. #2  
    Member Market Banned Market Banned

    Robin Spud's Avatar
    Join Date
    Aug 2008
    Age
    28
    Posts
    2,338
    Thanks given
    46
    Thanks received
    73
    Rep Power
    1068
    Quote Originally Posted by Kieran JR View Post
    The Catch or Specify Requirement:
    Valid Java programming language code must honor the Catch or Specify Requirement. This means that code that might throw certain exceptions must be enclosed by either of the following:

    A try statement that catches the exception. The try must provide a handler for the exception
    A method that specifies that it can throw the exception. The method must provide a throws clause that lists the exception

    Can someone show me the block of code which explains the try statement which catches the exception.
    Also the method that specifies that it can throw the exception, this would be much appreciated
    Code:
    	public void catchexample(){
    		try {
    		
    		//codehere
    		
    		} catch(IOException E){
    			E.printStackTrace();
    		}
    	}
    ILY Stewie.
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Oct 2009
    Posts
    67
    Thanks given
    0
    Thanks received
    1
    Rep Power
    163
    So thats block of code there is a try statement?
    And thank you for taking the time to post it repped.
    нσтуυтє'ѕ 566

    Proud Tester/Admin For нσтуυтє
    Reply With Quote  
     

  4. #4  
    Registered Member
    king free's Avatar
    Join Date
    Sep 2007
    Posts
    226
    Thanks given
    0
    Thanks received
    1
    Rep Power
    89
    Code:
    void test() throws Exception {
    	if(var == null)
    		throw new Exception("Var is null");
    	System.out.println(var);
    }
    What the above method does is throw an Exception if the Object var is null, otherwise it will be printed to System.out

    To catch any errors thrown by this method you can do this:

    Code:
    try {
    		test();
    } catch(Exception e) {
    		System.out.println(e.getMessage());
    }
    what this will do is if test() throws an exception, the error message from the exception is printed to console.
    DON'T GET v&

    Reply With Quote  
     

  5. #5  
    Registered Member

    Join Date
    Oct 2009
    Posts
    67
    Thanks given
    0
    Thanks received
    1
    Rep Power
    163
    Thank you very much king i now understand
    repped
    нσтуυтє'ѕ 566

    Proud Tester/Admin For нσтуυтє
    Reply With Quote  
     

  6. #6  
    Community Veteran


    Join Date
    Jan 2008
    Posts
    2,664
    Thanks given
    493
    Thanks received
    627
    Rep Power
    980
    nvm.
    ~iKilem
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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