@@ -102,11 +102,11 @@ void generateCode(SwiftWriter swiftWriter, String javaFullName, String swiftType
102102 }
103103
104104 if (returnSwiftType == null ) {
105- swiftWriter .emit (") {\n " );
105+ swiftWriter .emit (String . format ( ")%s {\n ", isThrown ? " throws" : "" ) );
106106 }
107107 else {
108108 String returnParamType = isReturnTypeOptional ? returnSwiftType .swiftType + "?" : returnSwiftType .swiftType ;
109- swiftWriter .emit (String .format (") -> %s {\n " , returnParamType ));
109+ swiftWriter .emit (String .format (")%s -> %s {\n " , isThrown ? " throws" : " " , returnParamType ));
110110 }
111111
112112 for (SwiftParamDescriptor param : params ) {
@@ -173,20 +173,36 @@ else if (isReturnTypeOptional) {
173173 }
174174
175175 if (returnSwiftType != null ) {
176- swiftWriter .emit (String .format (") else { %s }\n " , isReturnTypeOptional ? "return nil" : "fatalError(\" Don't support nil here!\" )" ));
176+ swiftWriter .emit (") else {" );
177+ swiftWriter .emitStatement ("if let throwable = JNI.ExceptionCheck() {" );
178+ if (isThrown ) {
179+ swiftWriter .emitStatement ("throw NSError(domain: \" JavaException\" , code: 1)" );
180+ }
181+ else {
182+ swiftWriter .emitStatement ("fatalError(\" Don't support exception here!\" )" );
183+ }
184+ swiftWriter .emitStatement ("} else {" );
185+ if (isReturnTypeOptional ) {
186+ swiftWriter .emitStatement ("return nil" );
187+ }
188+ else {
189+ swiftWriter .emitStatement ("fatalError(\" Don't support nil here!\" )" );
190+ }
191+ swiftWriter .emitStatement ("}" );
192+ swiftWriter .emitStatement ("}" );
177193 }
178194 else {
179195 swiftWriter .emit (")\n " );
180- }
181196
182- swiftWriter .emitStatement ("if let throwable = JNI.ExceptionCheck() {" );
183- if (isThrown ) {
184- swiftWriter .emitStatement ("throw NSError(domain: \" JavaException\" , code: 1)" );
185- }
186- else {
187- swiftWriter .emitStatement ("fatalError(\" JavaException\" )" );
197+ swiftWriter .emitStatement ("if let throwable = JNI.ExceptionCheck() {" );
198+ if (isThrown ) {
199+ swiftWriter .emitStatement ("throw NSError(domain: \" JavaException\" , code: 1)" );
200+ }
201+ else {
202+ swiftWriter .emitStatement ("fatalError(\" JavaException\" )" );
203+ }
204+ swiftWriter .emitStatement ("}" );
188205 }
189- swiftWriter .emitStatement ("}" );
190206
191207 if (returnSwiftType != null ) {
192208 swiftWriter .emitStatement ("do {" );
0 commit comments