FAQ: Debugging - Exception Handling

This community-built FAQ covers the “Exception Handling” exercise from the lesson “Debugging”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Java

FAQs on the exercise Exception Handling

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Therre is not an explanation of how to use the Try/Catch on this part of the lesson page 5 in the code. I had to go elsewhere to figure out how to use it.

2 Likes

why is there a e after the error name?

2 Likes

You may want to look at the Java documentation:
The structure for try/catch error handling is:

try {

} catch (ExceptionType name) {

} catch (ExceptionType name) {

}

So the “ArithmeticException” is the ExeptionType and “e” is the name of the exeption.

I guess it would have been nice if this were explained in the lesson.

4 Likes

I found the solution here:

try and catch

hey everyone,here’s my solution

public class Main{
  public static void main(String[] args) {
   int width = 0;
   int length = 40;
   try{
    int ratio = length / width;
   }
   catch(ArithmeticException e){
    System.err.println("ArithmeticException: " + e.getMessage());
   }
 }
}

but this answer did not pass, I’m confuse.
Is there any idea?

1 Like

I copied this code and it passed all three tests.

Common errors I ran into on this exercise:

  • Using System.out.println instead of System.err.println
    - This causes the output to print white and will not pass test

Hi this is my code but it just won’t pass. What could be the issue. I also tried code that was given above, still no luck.
And view solution is stuck on loading.

public class Main{

public static void main(String args) {
int width = 0;
int length = 40;

try{
int ratio = length / width;
}catch (ArithmeticException e) {
System.err.println("ArithmeticException: " + e.getMessage());
}

}
}