CompilerException explicit handling
jorge-lavin opened this issue · 1 comments
Based on the following two observations:
-
The method
public CompilationPackage compile(Map<String, String> classesToCompile) throws CompilerException
of the classInMemoryCompiler
declares that throws that Exception, therefore enforces to be handled explictly. Of course same applies tosingleCompile
-
In the tl;dr use case this exception is not handled, probably delegated to the
main(String[] args)
method or a unit test
Three proposals for a more flexible (end user point of view) approach, the three of them imply removing the explicit throws
of the methods:
-
Provide a null-like
CompilationPackage
so thatBaseCompilationPackage
is an interface that is implemented byNullCompilationPackage
andCompilationPackage
(say). -
Provide a way to access the
compilationReport
in theCompilationPackage
so that the user of the compiler can decide what to do with the CompilationPackage result. -
A combination of both 1 and 2.
A use case is an interface declaring a single method such as:
public interface CompilationPackageGenerator<T> {
CompilationPackage compile (T t);
}
whose implementation may be
@Override
public CompilationPackage compile(Foo foo)
{
HashMap<String, String> classes = irrelevantSourceCodeSupplier(foo);
try
{
return inMemoryCompiler.compile(classes);
}
catch (InMemoryCompiler.CompilerException e)
{
e.printStackTrace();
}
return null;
}
The return null
is the part that lead me to open this ticket. I don't want to add throws CompileException
to the interface.
Closing this issue as this concern should be covered by the latest code version.