summaryrefslogtreecommitdiff
path: root/swift/src
diff options
context:
space:
mode:
authorJoe George <joe@zeroc.com>2019-03-15 16:43:08 -0400
committerJoe George <joe@zeroc.com>2019-03-15 16:47:15 -0400
commit73d500babb129c583dc46903aa5586e387524f9b (patch)
treec21f077cd7d525d4985683ced72f843d9f59bb07 /swift/src
parentBuffer updates (diff)
downloadice-73d500babb129c583dc46903aa5586e387524f9b.tar.bz2
ice-73d500babb129c583dc46903aa5586e387524f9b.tar.xz
ice-73d500babb129c583dc46903aa5586e387524f9b.zip
Add RuntimeError
Diffstat (limited to 'swift/src')
-rw-r--r--swift/src/Ice/Exception.swift13
-rw-r--r--swift/src/Ice/Globals.swift2
-rw-r--r--swift/src/Ice/LocalExceptionFactory.swift6
-rw-r--r--swift/src/IceObjc/IceObjcException.h (renamed from swift/src/IceObjc/IceObjcLocalException.h)5
-rw-r--r--swift/src/IceObjc/IceObjcIceUtil.h8
-rw-r--r--swift/src/IceObjc/IceUtil.mm10
-rw-r--r--swift/src/IceObjc/Util.mm10
-rw-r--r--swift/src/IceObjc/module.map2
8 files changed, 40 insertions, 16 deletions
diff --git a/swift/src/Ice/Exception.swift b/swift/src/Ice/Exception.swift
index 67b7613ebbb..948633255d2 100644
--- a/swift/src/Ice/Exception.swift
+++ b/swift/src/Ice/Exception.swift
@@ -67,6 +67,19 @@ public extension UserException {
}
}
+// Used to wrap C++ std::exception messages
+public struct RuntimeError: Error, CustomStringConvertible {
+ let message: String
+
+ public var description: String {
+ return message
+ }
+
+ init(_ message: String) {
+ self.message = message
+ }
+}
+
#warning("TODO: CustomStringConvertible impl")
// TODO: All LocalExceptions should be CustomStringConvertible and print detailed messages
// like C++ (by calling IceUtilInternal::errorToString from ObjC)
diff --git a/swift/src/Ice/Globals.swift b/swift/src/Ice/Globals.swift
index b5205a0f0c1..ef94d4c78b1 100644
--- a/swift/src/Ice/Globals.swift
+++ b/swift/src/Ice/Globals.swift
@@ -11,7 +11,7 @@ import IceObjc
// Factories are registed once, when this file is loaded
private let initialized: Bool = {
- ICEUtil.registerFactories(localException: LocalExceptionFactory.self,
+ ICEUtil.registerFactories(exception: ExceptionFactory.self,
connectionInfo: ConnectionInfoFactory.self,
endpointInfo: EndpointInfoFactory.self)
return true
diff --git a/swift/src/Ice/LocalExceptionFactory.swift b/swift/src/Ice/LocalExceptionFactory.swift
index 947d31b5e8f..d270c1101e8 100644
--- a/swift/src/Ice/LocalExceptionFactory.swift
+++ b/swift/src/Ice/LocalExceptionFactory.swift
@@ -9,7 +9,7 @@
import IceObjc
-class LocalExceptionFactory: ICELocalExceptionFactory {
+class ExceptionFactory: ICEExceptionFactory {
static func initializationException(_ reason: String, file: String, line: Int) -> Error {
return InitializationException(reason: reason, file: file, line: line)
}
@@ -302,4 +302,8 @@ class LocalExceptionFactory: ICELocalExceptionFactory {
static func protocolException(_ reason: String, file: String, line: Int) -> Error {
return ProtocolException(reason: reason, file: file, line: line)
}
+
+ static func runtimeError(_ message: String) -> Error {
+ return RuntimeError(message)
+ }
}
diff --git a/swift/src/IceObjc/IceObjcLocalException.h b/swift/src/IceObjc/IceObjcException.h
index a83cf82149c..524bda42fe9 100644
--- a/swift/src/IceObjc/IceObjcLocalException.h
+++ b/swift/src/IceObjc/IceObjcException.h
@@ -11,7 +11,7 @@
NS_ASSUME_NONNULL_BEGIN
-@protocol ICELocalExceptionFactory
+@protocol ICEExceptionFactory
+(NSError*) initializationException:(NSString*)reason file:(NSString*)file line:(size_t)line;
+(NSError*) pluginInitializationException:(NSString*)reason file:(NSString*)file line:(size_t)line;
+(NSError*) collocationOptimizationException:(NSString*)file line:(size_t)line;
@@ -89,6 +89,9 @@ NS_ASSUME_NONNULL_BEGIN
+(NSError*) encapsulationException:(NSString*)reason file:(NSString*)file line:(size_t)line;
+(NSError*) marshalException:(NSString*)reason file:(NSString*)file line:(size_t)line;
+(NSError*) protocolException:(NSString*)reason file:(NSString*)file line:(size_t)line;
+
+// For generic std::exception
++(NSError*) runtimeError:(NSString*)message;
@end
NS_ASSUME_NONNULL_END
diff --git a/swift/src/IceObjc/IceObjcIceUtil.h b/swift/src/IceObjc/IceObjcIceUtil.h
index 42127925008..d958c136e86 100644
--- a/swift/src/IceObjc/IceObjcIceUtil.h
+++ b/swift/src/IceObjc/IceObjcIceUtil.h
@@ -10,7 +10,7 @@
#import "IceObjcCommunicator.h"
#import "IceObjcConnection.h"
#import "IceObjcEndpoint.h"
-#import "IceObjcLocalException.h"
+#import "IceObjcException.h"
#import "IceObjcLogger.h"
#import "IceObjcProperties.h"
@@ -20,15 +20,15 @@ NS_ASSUME_NONNULL_BEGIN
// Utility methods
//
@interface ICEUtil: NSObject
-@property (class, nonatomic, readonly) Class<ICELocalExceptionFactory> localExceptionFactory;
+@property (class, nonatomic, readonly) Class<ICEExceptionFactory> exceptionFactory;
@property (class, nonatomic, readonly) Class<ICEConnectionInfoFactory> connectionInfoFactory;
@property (class, nonatomic, readonly) Class<ICEEndpointInfoFactory> endpointInfoFactory;
//This method should only be called once to guarenteed thread safety
-+(BOOL) registerFactories:(Class<ICELocalExceptionFactory>)localException
++(BOOL) registerFactories:(Class<ICEExceptionFactory>)exception
connectionInfo:(Class<ICEConnectionInfoFactory>)connectionInfo
endpointInfo:(Class<ICEEndpointInfoFactory>)endpointInfo
-NS_SWIFT_NAME(registerFactories(localException:connectionInfo:endpointInfo:));
+NS_SWIFT_NAME(registerFactories(exception:connectionInfo:endpointInfo:));
+(nullable ICECommunicator*) initialize:(NSArray*)swiftArgs
properties:(ICEProperties* _Null_unspecified)properties
diff --git a/swift/src/IceObjc/IceUtil.mm b/swift/src/IceObjc/IceUtil.mm
index efee414e27a..5a6f348a8a1 100644
--- a/swift/src/IceObjc/IceUtil.mm
+++ b/swift/src/IceObjc/IceUtil.mm
@@ -31,13 +31,13 @@ namespace
}
@implementation ICEUtil
-static Class<ICELocalExceptionFactory> _localExceptionFactory;
+static Class<ICEExceptionFactory> _exceptionFactory;
static Class<ICEConnectionInfoFactory> _connectionInfoFactory;
static Class<ICEEndpointInfoFactory> _endpointInfoFactory;
-+(Class<ICELocalExceptionFactory>) localExceptionFactory
++(Class<ICEExceptionFactory>) exceptionFactory
{
- return _localExceptionFactory;
+ return _exceptionFactory;
}
@@ -51,11 +51,11 @@ static Class<ICEEndpointInfoFactory> _endpointInfoFactory;
return _endpointInfoFactory;
}
-+(BOOL) registerFactories:(Class<ICELocalExceptionFactory>)localException
++(BOOL) registerFactories:(Class<ICEExceptionFactory>)exception
connectionInfo:(Class<ICEConnectionInfoFactory>)connectionInfo
endpointInfo:(Class<ICEEndpointInfoFactory>)endpointInfo
{
- _localExceptionFactory = localException;
+ _exceptionFactory = exception;
_connectionInfoFactory = connectionInfo;
_endpointInfoFactory = endpointInfo;
return true;
diff --git a/swift/src/IceObjc/Util.mm b/swift/src/IceObjc/Util.mm
index fc8f3b0ca36..52a238ebabd 100644
--- a/swift/src/IceObjc/Util.mm
+++ b/swift/src/IceObjc/Util.mm
@@ -7,7 +7,7 @@
//
// **********************************************************************
-#import "IceObjcLocalException.h"
+#import "IceObjcException.h"
#import "IceObjcIceUtil.h"
#import "IceObjcUtil.h"
@@ -28,12 +28,12 @@ convertException(const std::exception_ptr& excPtr)
NSError*
convertException(const std::exception& exc)
{
+ Class<ICEExceptionFactory> factory = [ICEUtil exceptionFactory];
+
if(dynamic_cast<const Ice::LocalException*>(&exc))
{
auto iceEx = dynamic_cast<const Ice::LocalException*>(&exc);
- Class<ICELocalExceptionFactory> factory = [ICEUtil localExceptionFactory];
-
try
{
iceEx->ice_throw();
@@ -309,6 +309,10 @@ convertException(const std::exception& exc)
return [factory localException:toNSString(e.ice_file()) line:e.ice_line()];
}
}
+ else
+ {
+ return [factory runtimeError:toNSString(exc.what())];
+ }
return nil;
}
diff --git a/swift/src/IceObjc/module.map b/swift/src/IceObjc/module.map
index c35a660f891..61b5d2df180 100644
--- a/swift/src/IceObjc/module.map
+++ b/swift/src/IceObjc/module.map
@@ -6,7 +6,7 @@ module IceObjc {
header "IceObjcIceUtil.h"
header "IceObjcImplicitContext.h"
header "IceObjcInputStream.h"
- header "IceObjcLocalException.h"
+ header "IceObjcException.h"
header "IceObjcLocalObject.h"
header "IceObjcLogger.h"
header "IceObjcObjectPrx.h"