Results 1 to 2 of 2
  1. #1
    jaavanewb is offline Member
    Join Date
    Mar 2017
    Posts
    13
    Rep Power
    0

    Default try catch clarification

    I'm a bit confused about testing for exceptions. Does a try statement simply test? Or does it actually perform the code within it. For example
    if I have a statement such that:

    Java Code:
    boolean whatAmI = true;
    try{
           whatAmI = false
            throw new Exception();
    }catch(Exception e){
    System.out.println( e.getMessage());
    would WhatAmI remain true? would the message be printed (assuming no syntax errors)

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,342
    Rep Power
    12

    Default Re: try catch clarification

    Exception catching does not roll back actions that have already been done. In your example, whatAmI would be false after line 6. But, consider this: move the throw statement to line 3 (swap it with the assignment) and then what do you thing will happen?

Similar Threads

  1. Clarification needed
    By jmohandos304 in forum New To Java
    Replies: 6
    Last Post: 07-24-2014, 03:49 PM
  2. Need a bit of clarification on JNI
    By FlyNn in forum Advanced Java
    Replies: 9
    Last Post: 03-11-2012, 10:38 PM
  3. Clarification of FileOutputStream
    By rogi85 in forum New To Java
    Replies: 4
    Last Post: 08-03-2011, 12:02 PM
  4. Struts Clarification
    By vinothkumarrvk in forum Web Frameworks
    Replies: 0
    Last Post: 02-26-2010, 02:24 PM
  5. HELP! need clarification
    By ptsofathrty in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 08:02 AM

Tags for this Thread

Posting Permissions

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