diff --git a/llm_toolkit/prompt_builder.py b/llm_toolkit/prompt_builder.py
index ca4c8af6f7..c5806e05f7 100644
--- a/llm_toolkit/prompt_builder.py
+++ b/llm_toolkit/prompt_builder.py
@@ -547,6 +547,7 @@ def __init__(self,
self._template_dir = template_dir
self.benchmark = benchmark
self.project_url = self._find_project_url(self.benchmark.project)
+ self.exceptions = set(self.benchmark.exceptions)
# Load templates.
self.base_template_file = self._find_template(template_dir, 'jvm_base.txt')
@@ -622,9 +623,12 @@ def _format_target_method(self, signature: str) -> str:
def _format_exceptions(self) -> str:
"""Formats the exception thrown from this method or constructor."""
- if self.benchmark.exceptions:
- return '' + '\n'.join(
- self.benchmark.exceptions) + ''
+ if self.exceptions:
+ exception_str_list = [
+ f'{exp}' for exp in self.exceptions
+ ]
+ return '\n' + '\n'.join(
+ exception_str_list) + '\n'
return ''
@@ -797,6 +801,7 @@ def _format_constructors(self) -> str:
constructor_sig = ctr.get('function_signature')
if constructor_sig:
constructors.append(f'{constructor_sig}')
+ self.exceptions.update(ctr.get('exceptions', []))
if constructors:
ctr_str = '\n'.join(constructors)
@@ -810,6 +815,7 @@ def _format_constructors(self) -> str:
function_sig = func.get('function_signature')
if not function_sig:
continue
+ self.exceptions.update(func.get('exceptions', []))
if is_static:
functions.append(f'- {function_sig}
')
else:
diff --git a/prompts/template_xml/jvm_requirement.txt b/prompts/template_xml/jvm_requirement.txt
index a8cde9887e..212aa246d3 100644
--- a/prompts/template_xml/jvm_requirement.txt
+++ b/prompts/template_xml/jvm_requirement.txt
@@ -9,6 +9,7 @@
- Please avoid using any multithreading or multi-processing approach.
- Please add import statements for necessary classes, except for classes in the java.lang package.
- You must create the object before calling the target method.
+- You must catch java.lang.UnsupportOperationException.
- Please use {HARNESS_NAME} as the Java class name.
- {STATIC_OR_INSTANCE}
- Do not create new variables with the same names as existing variables.