lundi 11 avril 2016

Regarding Writing a Custom Class Exception in Java

I am trying to complete an activity that my professor for my Computer Science course has assigned, and I am not quite sure what he means by this, look at number 4:

enter image description here

Here is what i have so far:

package ExceptionsActivity;

public class Exceptions {

public static void f1(int x) throws XisFiveException{
    if (x == 5){
        throw new XisFiveException("X cannot be 5");
    }
    else {
        System.out.println("Success, x = ");
    }
}

public static void f2_1(int x) throws XisFiveException{
    try {
        f1(x);
    } 
    catch (XisFiveException e) {
        f1(x + 1);
    }
}

public static void f2_2(int x) throws XisFiveException{

}
public static void main(String[] args) {

}

}

As you can see I have wrote the method f1 and f2_1 which is what question number 2 is asking for. I intended on putting the solution for question four in f2_2. I am not quite sure what to do for number 4 and any advice as to what direction to head in would greatly be appreciated. Thank you for your time!





Aucun commentaire:

Enregistrer un commentaire