Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define my own errors in Eclipse?

Tags:

java

eclipse

Is there a way to define my own compile errors for Eclipse? I want to throw compile errors if certain objects are not instantiated.

To give you exactly what I want to do:

I have an Assets class that holds null variables for all resources (images, sounds, etc.) and a LoadingScreen class that initializes all of these resource objects. If I add a resource to the Assets class but not to the LoadingScreen class, it will mess up the whole application. I want to see an error in eclipse if the variables in the Assets class are not also initialized in LoadingScreen.

Is this possible?

like image 241
Michael Auderer Avatar asked Aug 17 '13 04:08

Michael Auderer


People also ask

How do I resolve an error in eclipse?

The Quick Fix dialog can also be displayed by right clicking on the error item in the Problems view and selecting the Quick Fix menu item.

What is the error Cannot be resolved to a type?

This means that your project isn't setup to include the JUnit libraries when it compiles; JUnit is not included in the Java runtime libraries (JRE System Library) so you have to add it to the build path.


2 Answers

I agree with LaurentG, I think you should solve this problem at Java level. For example, you could have a method which does at the end some final checks where you would check if any of your resources have a null pointer and throw a custom exception if you detect any.

if (resourceObject==null) {
throw new CustomException("Null pointer for resource object detected");
}

public class CustomException extends Exception {
   public CustomException (String errorMsg) {
   super(errorMsg);
  }
}

However, there are too many unknowns to give a really precise and accurate answer. Some code would definitely help.

like image 78
Alex Goja Avatar answered Oct 30 '22 07:10

Alex Goja


I think you can create a new plugin or modify jdt. The errors are detected when compiling using eclipse Batch compiler. You should take a look at this, and this.

like image 41
Vinz243 Avatar answered Oct 30 '22 07:10

Vinz243