user8689296
user8689296

Reputation:

Exception error in method not using exception

I'm having an issue

TEST CODE:

    addList.add("Task 30", 30);

    System.out.println(addList.get

NOTE: For whatever reason the method actuallly using the exception has no compiler errors but the one that doesn't use it is. Why is that?

Upvotes: 2

Views: 47

Answers (1)

Code-Apprentice
Code-Apprentice

Reputation: 83527

testAdd() does not have any errors because you catch the exception. testGet() gives errors because you do not have a catch nor do you declare that the method can throw the exception. For more details about exceptions, read the official Java tutorial, particularly the section on catch or specify.

Upvotes: 1

Related Questions