mustardtiger10
mustardtiger10

Reputation: 47

What is javax.xml.bind?

I'm very new to exception handling, and while writing this program for school I had some strange errors come up.

In my program I had a class for "ValidationException" which extends "Exception", and 3 other classes.

In one of the classes several of the methods throw to the "ValidationException" class, and in the other class I have several try and catch blocks where they catch a "ValidationException".

Anyways, in the catch statements it wouldn't allow me to put "catch(ValidationException e)", it forced me to put "catch(javax.xml.bind.ValidationException e)".

After doing this it worked just fine. The exact same thing happened with my j-unit test cases.

Anyways, I'm just wondering if I screwed something up somehow! If anyone might have an idea what caused this or what this javax.xml.bind is that would be great!

Upvotes: 0

Views: 290

Answers (1)

dr.java
dr.java

Reputation: 46

Problem was collision of class names. Within your code, your custom ValidationException was in scope by default, thereby masking the ValidationException class within javax.xml.bind package. Since the thrown exception is a different ValidationException class than in scope, you were simply required to identify the correct package. Had you named your class MyValidationException, you would not have had to specify the package prefix within the catch.

Think of "package" as being similar to "path" to the specific class or set of classes.

Upvotes: 2

Related Questions