Skip to content

Commit ac4fc3e

Browse files
committed
Removed some debug logging. #28
1 parent 730b18e commit ac4fc3e

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2021 Web Lite Solutions Corp..
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package ca.weblite.objc;
17+
18+
import java.lang.reflect.Method;
19+
20+
/**
21+
* Exception that may be thrown when failure occurs while trying to invoke
22+
* a method in response to a selector.
23+
* @author shannah
24+
*/
25+
public class NSMessageInvocationException extends RuntimeException {
26+
private String selectorName;
27+
private Method method;
28+
29+
/**
30+
* Creates a new instance of this exception.
31+
* @param selectorName The objective-c selector that was being handled.
32+
* @param method The method that was being executed.
33+
* @param cause The cause of the exception.
34+
*/
35+
public NSMessageInvocationException(String selectorName, Method method, Throwable cause) {
36+
super(String.format("Method invocation for selector %s caused exception. Method: %s", selectorName, method), cause);
37+
}
38+
39+
/**
40+
* The name of the Objective-C selector that was being called.
41+
* @return
42+
*/
43+
public String getSelectorName() {
44+
return selectorName;
45+
}
46+
47+
/**
48+
* The method that was being executed when this exception occurred.
49+
* @return
50+
*/
51+
public Method getMethod() {
52+
return method;
53+
}
54+
}

src/main/java/ca/weblite/objc/NSObject.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ public void forwardInvocation(Pointer invocation){
449449
* through Java so that it has a chance to process it.
450450
* @see <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSInvocation_Class/Reference/Reference.html">NSInvocation Class Reference</a>
451451
* @see <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSProxy_Class/Reference/Reference.html">NSProxy forwardInvocation Documentation</a>
452+
*
453+
* @throws NSMessageInvocationException If an exception occurs while attempting to invoke the method.
452454
*/
453455
@Override
454456
public void forwardInvocation(long linvocation) {
@@ -461,8 +463,8 @@ public void forwardInvocation(long linvocation) {
461463
Proxy pSig = new Proxy(rawClient, sig);
462464
Pointer selector = msgPointer(invocation, "selector");
463465
long numArgs = (Long)pSig.send("numberOfArguments");
464-
465-
Method method = methodForSelector(selName(selector));
466+
String selName = selName(selector);
467+
Method method = methodForSelector(selName);
466468
if ( method != null){
467469

468470
Msg message = (Msg)method.getAnnotation(Msg.class);
@@ -535,9 +537,7 @@ public void forwardInvocation(long linvocation) {
535537

536538
return;
537539
} catch (Exception ex){
538-
LOG.log(Level.SEVERE, String.format("Method invocation caused exception: %s", method));
539-
ex.printStackTrace(System.err);
540-
throw new RuntimeException(ex);
540+
throw new NSMessageInvocationException(selName, method, ex);
541541
}
542542

543543
}

src/main/java/ca/weblite/objc/RuntimeUtils.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -893,15 +893,6 @@ public static ByReference getAsReferenceWrapper(Object val, String signature){
893893
return null;
894894
case '^':
895895
default:
896-
////System.out.println("Outputting pointer by reference for value "+val+" and signature "+signature);
897-
if ( val == null ){
898-
try {
899-
throw new RuntimeException("Checking stack trace for val "+val+" and signature "+signature);
900-
901-
} catch (Exception ex){
902-
ex.printStackTrace(System.err);
903-
}
904-
}
905896
if ( Pointer.class.isInstance(val) ){
906897
return new PointerByReference((Pointer)val);
907898
} else if ( Long.class.isInstance(val) || long.class.isInstance(val)){

0 commit comments

Comments
 (0)