Skip to content

Commit a60c0de

Browse files
author
Matthias Fuchs
committed
some exception refactoring
1 parent 2ea7c1e commit a60c0de

File tree

3 files changed

+119
-10
lines changed

3 files changed

+119
-10
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1020"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "65152903163458B4002A41D8"
18+
BuildableName = "libjcocoa.dylib"
19+
BlueprintName = "libjcocoa"
20+
ReferencedContainer = "container:libjcocoa.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
<AdditionalOptions>
33+
</AdditionalOptions>
34+
</TestAction>
35+
<LaunchAction
36+
buildConfiguration = "Debug"
37+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
38+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
39+
launchStyle = "0"
40+
useCustomWorkingDirectory = "NO"
41+
ignoresPersistentStateOnLaunch = "NO"
42+
debugDocumentVersioning = "YES"
43+
debugServiceExtension = "internal"
44+
allowLocationSimulation = "YES">
45+
<MacroExpansion>
46+
<BuildableReference
47+
BuildableIdentifier = "primary"
48+
BlueprintIdentifier = "65152903163458B4002A41D8"
49+
BuildableName = "libjcocoa.dylib"
50+
BlueprintName = "libjcocoa"
51+
ReferencedContainer = "container:libjcocoa.xcodeproj">
52+
</BuildableReference>
53+
</MacroExpansion>
54+
<AdditionalOptions>
55+
</AdditionalOptions>
56+
</LaunchAction>
57+
<ProfileAction
58+
buildConfiguration = "Release"
59+
shouldUseLaunchSchemeArgsEnv = "YES"
60+
savedToolIdentifier = ""
61+
useCustomWorkingDirectory = "NO"
62+
debugDocumentVersioning = "YES">
63+
<MacroExpansion>
64+
<BuildableReference
65+
BuildableIdentifier = "primary"
66+
BlueprintIdentifier = "65152903163458B4002A41D8"
67+
BuildableName = "libjcocoa.dylib"
68+
BlueprintName = "libjcocoa"
69+
ReferencedContainer = "container:libjcocoa.xcodeproj">
70+
</BuildableReference>
71+
</MacroExpansion>
72+
</ProfileAction>
73+
<AnalyzeAction
74+
buildConfiguration = "Debug">
75+
</AnalyzeAction>
76+
<ArchiveAction
77+
buildConfiguration = "Release"
78+
revealArchiveInOrganizer = "YES">
79+
</ArchiveAction>
80+
</Scheme>

native/libjcocoa/WLJavaProxy.m

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ -(WLJavaProxy*)init:(jobject)thePeer
3939

4040
return self;
4141
} @catch (NSException *e) {
42-
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
4342
NSLog(@"Exception: %@", e);
43+
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
4444
}
4545
}
4646

@@ -59,8 +59,8 @@ -(void)dealloc
5959
//JNF_COCOA_EXIT(env);
6060
}
6161
} @catch (NSException *e) {
62-
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
6362
NSLog(@"Exception: %@", e);
63+
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
6464
}
6565
}
6666

@@ -74,8 +74,8 @@ +(void)setJVM:(JavaVM*)theJvm
7474
jvm = theJvm;
7575
}
7676
} @catch (NSException *e) {
77-
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
7877
NSLog(@"Exception: %@", e);
78+
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
7979
}
8080
}
8181

@@ -89,31 +89,38 @@ -(NSMethodSignature*)methodSignatureForSelector:(SEL)sel
8989
if ( attach == 0 ){
9090
//JNF_COCOA_ENTER(env);
9191
signature = (NSMethodSignature*)(*env)->CallLongMethod(env, peer, jMethodSignatureForSelector, sel);
92+
93+
if (!signature) {
94+
signature = [@"" methodSignatureForSelector:sel];
95+
}
96+
9297
//JNF_COCOA_EXIT(env);
9398
}
9499
//(*jvm)->DetachCurrentThread(jvm);
95100
return signature;
96101
} @catch (NSException *e) {
97-
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
98102
NSLog(@"Exception: %@", e);
103+
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
99104
}
100105
}
101106

102107
-(void)forwardInvocation:(NSInvocation *)invocation
103108
{
104109
JNIEnv *env=0;
110+
SEL aSelector = [invocation selector];
111+
int attach = (*jvm)->AttachCurrentThread(jvm, (void**)&env, NULL);
105112

106113
@try {
107-
int attach = (*jvm)->AttachCurrentThread(jvm, (void**)&env, NULL);
108-
if ( attach == 0 ){
114+
if ( attach == 0 ) {
109115
//JNF_COCOA_ENTER(env);
110116
(*env)->CallVoidMethod(env, peer, jForwardInvocation, invocation);
111117
//JNF_COCOA_EXIT(env);
112118
}
113119
//(*jvm)->DetachCurrentThread(jvm);
114120
} @catch (NSException *e) {
115-
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
116-
NSLog(@"Exception: %@", e);
121+
NSString *message = [NSString stringWithFormat:@"Selector '%@' caused exception: %@", NSStringFromSelector(aSelector), e.reason];
122+
NSLog(@"%@", message);
123+
[JavaUtil throwJavaException: env withMessage: [message UTF8String] ];
117124
}
118125
}
119126

@@ -132,8 +139,8 @@ -(BOOL)respondsToSelector:(SEL)aSelector
132139
//(*jvm)->DetachCurrentThread(jvm);
133140
return response==1?TRUE:FALSE;
134141
} @catch (NSException *e) {
135-
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
136142
NSLog(@"Exception: %@", e);
143+
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
137144
}
138145
}
139146

@@ -148,8 +155,30 @@ -(jobject)javaPeer
148155
}
149156
return NULL;
150157
} @catch (NSException *e) {
151-
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
152158
NSLog(@"Exception: %@", e);
159+
[JavaUtil throwJavaException: env withMessage: [[e reason] UTF8String] ];
153160
}
154161
}
162+
163+
+ (NSSet<NSString *> *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
164+
// SEL theSelector = @selector(keyPathsForValuesAffectingValueForKey:);
165+
// NSMethodSignature *aSignature = [NSObject methodSignatureForSelector:theSelector];
166+
// NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature:aSignature];
167+
//
168+
// [anInvocation setSelector:theSelector];
169+
// [anInvocation setTarget:self];
170+
// [anInvocation setArgument:&key atIndex:1];
171+
//
172+
// [self forwardInvocation:anInvocation];
173+
//
174+
// void *result;
175+
// [anInvocation getReturnValue:result];
176+
//
177+
// return result;
178+
179+
180+
NSSet *keyPaths = [[NSSet alloc] initWithObjects: key];
181+
return keyPaths;
182+
}
183+
155184
@end

0 commit comments

Comments
 (0)