Exception
Hello!
I have mad my own exception like this:
package example.nextgen.model;
publicclass ProductDescriptionMissingExceptionextends Exception{
private Throwable cause =null;
public ProductDescriptionMissingException(){
super();
}
public ProductDescriptionMissingException(String message){
super(message);
}
public ProductDescriptionMissingException(String message, Throwable cause){
super(message);
this.cause = cause;
}
public Throwable getCause(){
return cause;
}
publicvoid printStackTrace(java.io.PrintStream ps)
{
super.printStackTrace(ps);
if (cause !=null){
ps.println("Caused by:");
cause.printStackTrace(ps);
}
}
publicvoid printStackTrace(java.io.PrintWriter pw)
{
super.printStackTrace(pw);
if (cause !=null){
pw.println("Caused by:");
cause.printStackTrace(pw);
}
}
}
Then i try to do this:
throw new ProductDescriptionMissingException("Product description does not exist!");
I get the error message:
compile:
[javac] Compiling 16 source files to C:\KTH2\Objektorienterad_design\L3\with
-tests\build\classes
[javac] C:\KTH2\Objektorienterad_design\L3\with-tests\src\main\example\nextg
en\controller\Register.java:54: unreported exception example.nextgen.model.Produ
ctDescriptionMissingException; must be caught or declared to be thrown
[javac] throw new ProductDescriptionMissingException("Product de
scription does not exist!");
[javac]^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
BUILD FAILED
I import the exception class in the file where i try to throw it.
What am i doing wrong?

