[Bluetooth] Removed try/catch - part 3
authorTomasz Marciniak <t.marciniak@samsung.com>
Tue, 24 Feb 2015 08:16:48 +0000 (09:16 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Tue, 24 Feb 2015 15:04:08 +0000 (00:04 +0900)
[Verification] Code compiles without errors.

Change-Id: I8a0a558ae8ed8969cdcfe80290f648bcd436e775
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
src/bluetooth/bluetooth_adapter.cc
src/bluetooth/bluetooth_device.cc
src/bluetooth/bluetooth_health_channel.cc
src/bluetooth/bluetooth_health_profile_handler.cc
src/bluetooth/bluetooth_socket.cc

index 127ff08f64d0bb91266ce07521ca030f5765a5d3..9d73caf15d7cfcdeeaed62efe9200f7b9d4288dc 100644 (file)
@@ -1064,23 +1064,23 @@ void BluetoothAdapter::RegisterRFCOMMServiceByUUID(const picojson::value& data,
     const auto& name = FromJson<std::string>(args, "name");
 
     auto rfcomm = [this, uuid, name](const std::shared_ptr<picojson::value>& response) -> void {
-        try {
-            if (!this->is_initialized()) {
-                throw UnknownException("Bluetooth service is not initialized.");
-            }
-
-            if (!IsValidUUID(uuid)) {
-                throw InvalidValuesException("Wrong UUID");
-            }
+        PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+        if (!this->is_initialized()) {
+            result = PlatformResult(
+                ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+        }
 
-            if (this->get_powered()) {
-                bool is_registered = false;
-                int ret = bt_adapter_is_service_used(uuid.c_str(), &is_registered);
+        if (result.IsSuccess() && !IsValidUUID(uuid)) {
+            result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Wrong UUID");
+        }
 
-                if (BT_ERROR_NONE == ret && is_registered) {
-                    throw InvalidValuesException("Already registered");
-                }
+        if (result.IsSuccess() && this->get_powered()) {
+            bool is_registered = false;
+            int ret = bt_adapter_is_service_used(uuid.c_str(), &is_registered);
 
+            if (BT_ERROR_NONE == ret && is_registered) {
+                result = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
+            } else {
                 int socket = -1;
                 ret = bt_socket_create_rfcomm(uuid.c_str(), &socket);
 
@@ -1095,36 +1095,38 @@ void BluetoothAdapter::RegisterRFCOMMServiceByUUID(const picojson::value& data,
                                 registered_uuids_.insert(std::make_pair(uuid,
                                         std::make_pair(socket, false)));
 
-                                util::ReportSuccess(response->get<picojson::object>());
+                                ReportSuccess(response->get<picojson::object>());
                                 break;
                             }
 
                             case BT_ERROR_INVALID_PARAMETER: {
-                                throw InvalidValuesException("Invalid value");
+                                result = PlatformResult(
+                                    ErrorCode::INVALID_VALUES_ERR, "Invalid value");
                                 break;
                             }
 
                             default: {
-                                throw UnknownException("Unknown error");
+                                result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
                                 break;
                             }
                         }
                         break;
                     }
-
                     case BT_ERROR_INVALID_PARAMETER:
-                        throw InvalidValuesException("Invalid value");
+                        result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
                         break;
-
                     default:
-                        throw UnknownException("Unknown error");
+                        result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
                         break;
                 }
-            } else {
-                throw ServiceNotAvailableException("Bluetooth device is turned off");
             }
-        } catch (const PlatformException& err) {
-            util::ReportError(err, response->get<picojson::object>());
+        } else if (result.IsSuccess()) {
+            result = PlatformResult(
+                ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+        }
+
+        if (result.IsError()) {
+            ReportError(result, &response->get<picojson::object>());
         }
     };
 
@@ -1135,45 +1137,38 @@ void BluetoothAdapter::RegisterRFCOMMServiceByUUID(const picojson::value& data,
     TaskQueue::GetInstance().Queue<picojson::value>(rfcomm, rfcomm_response,
             std::shared_ptr<picojson::value>(new picojson::value(picojson::object())));
 
-    util::ReportSuccess(out);
+    ReportSuccess(out);
 }
 
 void BluetoothAdapter::UnregisterUUID(const std::string& uuid, int callback_handle) {
     LoggerD("Entered");
 
+    PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
     if (!IsValidUUID(uuid)) {
-        throw InvalidValuesException("Wrong UUID");
+        result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Wrong UUID");
     }
 
-    std::shared_ptr<picojson::value> response =
-            std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-
-    try {
-        if (is_powered_) {
-            auto iter = registered_uuids_.find(uuid);
-            if (iter != registered_uuids_.end()) {
-                if (BT_ERROR_NONE == bt_socket_destroy_rfcomm(iter->second.first)) {
-                    registered_uuids_.erase(iter);
-                } else {
-                    throw UnknownException("Unknown error");
-                }
-            }
-
-            if (registered_uuids_.size() == 0 &&
-                connection_requests_.size() == 0 &&
-                connected_sockets_.size() == 0) {
-                bt_socket_unset_connection_state_changed_cb();
+    if (result.IsSuccess() && is_powered_) {
+        auto iter = registered_uuids_.find(uuid);
+        if (iter != registered_uuids_.end()) {
+            if (BT_ERROR_NONE == bt_socket_destroy_rfcomm(iter->second.first)) {
+                registered_uuids_.erase(iter);
+            } else {
+                result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
             }
-        } else {
-            throw ServiceNotAvailableException("Bluetooth device is turned off");
         }
 
-        util::ReportSuccess(response->get<picojson::object>());
-    } catch (const PlatformException& err) {
-        util::ReportError(err, response->get<picojson::object>());
+        if (registered_uuids_.size() == 0 &&
+            connection_requests_.size() == 0 &&
+            connected_sockets_.size() == 0) {
+            bt_socket_unset_connection_state_changed_cb();
+        }
+    } else if (result.IsSuccess()){
+        result = PlatformResult(
+            ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
     }
 
-    util::AsyncResponse(callback_handle, response);
+    util::AsyncResponse(callback_handle, result);
 }
 
 void BluetoothAdapter::GetBluetoothProfileHandler(const picojson::value& data,
@@ -1183,6 +1178,8 @@ void BluetoothAdapter::GetBluetoothProfileHandler(const picojson::value& data,
     const auto& args = util::GetArguments(data);
     auto profile = FromJson<std::string>(args, "profileType");
 
+    PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+
     if (kBluetoothProfileHealth == profile) {
         bool supported = false;
         if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(kFeatureBluetoothHealth.c_str(),
@@ -1191,15 +1188,20 @@ void BluetoothAdapter::GetBluetoothProfileHandler(const picojson::value& data,
         }
 
         if (!supported) {
-            throw NotSupportedException("Bluetooth health profile is not supported");
+            result = PlatformResult(
+                ErrorCode::NOT_SUPPORTED_ERR, "Bluetooth health profile is not supported");
         } else {
             LoggerD("BT health profile is supported");
         }
     } else {
-        throw TypeMismatchException("Wrong profile type.");
+        result = PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Wrong profile type.");
     }
 
-    util::ReportSuccess(out);
+    if (result.IsSuccess()) {
+        ReportSuccess(out);
+    } else {
+        ReportError(result, &out);
+    }
 }
 
 void BluetoothAdapter::GetName(const picojson::value& /* data */, picojson::object& out) {
@@ -1212,7 +1214,9 @@ void BluetoothAdapter::GetAddress(const picojson::value& /* data */, picojson::o
     LoggerD("Entered");
 
     if (!is_initialized_) {
-        throw UnknownException("Bluetooth service is not initialized.");
+        ReportError(PlatformResult(
+            ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized."), &out);
+        return;
     }
 
     std::string str_address = "";
@@ -1388,44 +1392,43 @@ void BluetoothAdapter::ConnectToServiceByUUID(const std::string& address,
                                               double callback_handle) {
     LoggerD("Entered");
 
+    PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+
     if (!IsValidUUID(uuid)) {
-        throw InvalidValuesException("Wrong UUID");
+        result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Wrong UUID");
     }
 
-    try {
-        if (is_powered_) {
-            int ret = bt_socket_connect_rfcomm(address.c_str(), uuid.c_str());
-
-            switch (ret) {
-                case BT_ERROR_NONE: {
-                    LoggerD("bt_socket_connect_rfcomm() succeeded");
+    if (result.IsSuccess() && is_powered_) {
+        int ret = bt_socket_connect_rfcomm(address.c_str(), uuid.c_str());
 
-                    ConnectionRequestPtr request{new ConnectionRequest()};
-                    request->uuid_ = uuid;
-                    request->callback_handle_ = callback_handle;
-                    connection_requests_.insert(std::make_pair(address, request));
-
-                    bt_socket_set_connection_state_changed_cb(OnSocketConnected, this);
-                    break;
-                }
+        switch (ret) {
+            case BT_ERROR_NONE: {
+                LoggerD("bt_socket_connect_rfcomm() succeeded");
 
-                case BT_ERROR_INVALID_PARAMETER:
-                case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
-                    throw InvalidValuesException("Invalid value");
-                    break;
+                ConnectionRequestPtr request{new ConnectionRequest()};
+                request->uuid_ = uuid;
+                request->callback_handle_ = callback_handle;
+                connection_requests_.insert(std::make_pair(address, request));
 
-                default:
-                    throw UnknownException("Unknown error");
-                    break;
+                bt_socket_set_connection_state_changed_cb(OnSocketConnected, this);
+                break;
             }
-        } else {
-            throw ServiceNotAvailableException("Bluetooth device is turned off");
+
+            case BT_ERROR_INVALID_PARAMETER:
+            case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
+                result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+                break;
+            default:
+                result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
+                break;
         }
-    } catch (const PlatformException& e) {
-        std::shared_ptr<picojson::value> response =
-                std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-        util::ReportError(e, response->get<picojson::object>());
-        util::AsyncResponse(callback_handle, response);
+    } else if (result.IsSuccess()) {
+        result = PlatformResult(
+            ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+    }
+
+    if (result.IsError()) {
+        util::AsyncResponse(callback_handle, result);
     }
 }
 
@@ -1503,7 +1506,9 @@ void BluetoothAdapter::IsServiceConnected(const picojson::value& data, picojson:
 
     auto iter = registered_uuids_.find(uuid);
     if (iter == registered_uuids_.end()) {
-        throw InvalidValuesException("Invalid parameter was passed.");
+      ReportError(PlatformResult(
+          ErrorCode::INVALID_VALUES_ERR, "Invalid parameter was passed."), &out);
+      return;
     }
 
     util::ReportSuccess(picojson::value(iter->second.second), out);
index 6f05aa5b2f3d875a28f4ca25c41e21d73acf980a..77a39b5bcc10be6e5b8a60f2791e70c920f8a916 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "common/converter.h"
 #include "common/logger.h"
+#include "common/extension.h"
 
 #include "bluetooth_adapter.h"
 #include "bluetooth_class.h"
@@ -28,6 +29,7 @@ namespace extension {
 namespace bluetooth {
 
 using namespace common;
+using namespace common::tools;
 
 namespace {
 //device
@@ -118,6 +120,7 @@ void BluetoothDevice::GetBoolValue(const picojson::value& data, picojson::object
     const auto& address = FromJson<std::string>(args, "address");
     const auto& field = FromJson<std::string>(args, "field");
 
+    PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
     bool value = false;
     bt_device_info_s *info = nullptr;
     if (bt_adapter_get_bonded_device_info(address.c_str(), &info) == BT_ERROR_NONE &&
@@ -129,15 +132,18 @@ void BluetoothDevice::GetBoolValue(const picojson::value& data, picojson::object
         } else if (kDeviceIsConnected == field) {
             value = info->is_connected;
         } else {
-            bt_adapter_free_device_info(info);
-            throw UnknownException("Wrong field passed.");
+            result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Wrong field passed.");
         }
         bt_adapter_free_device_info(info);
     } else {
-        throw UnknownException("Unknown error");
+        result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
     }
 
-    util::ReportSuccess(picojson::value(value), out);
+    if (result.IsSuccess()) {
+        ReportSuccess(picojson::value(value), out);
+    } else {
+        ReportError(result, &out);
+    }
 }
 
 } // namespace bluetooth
index 0923a0f19f30989a9c68d5915a97713bf9916bba..ca248186a3d8b695de091f0141a4d229eafa4921 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "common/converter.h"
 #include "common/logger.h"
-#include "common/platform_exception.h"
+#include "common/extension.h"
 
 #include "bluetooth_device.h"
 #include "bluetooth_privilege.h"
@@ -30,6 +30,7 @@ namespace extension {
 namespace bluetooth {
 
 using namespace common;
+using namespace common::tools;
 
 namespace {
 const std::string kPeer = "peer";
@@ -50,7 +51,8 @@ void BluetoothHealthChannel::Close(const picojson::value& data , picojson::objec
     const auto& address = FromJson<std::string>(args, "address");
 
     if (BT_ERROR_NONE != bt_hdp_disconnect(address.c_str(), channel)) {
-        throw UnknownException("Unknown error");
+        ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+        return;
     }
 
     util::ReportSuccess(out);
@@ -75,7 +77,8 @@ void BluetoothHealthChannel::SendData(const picojson::value& data, picojson::obj
 
     if (BT_ERROR_NONE != bt_hdp_send_data(channel, data_ptr.get(), data_size)) {
         LoggerE("bt_hdp_send_data() failed");
-        throw UnknownException("Unknown error");
+        ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+        return;
     }
 
     util::ReportSuccess(picojson::value(static_cast<double>(data_size)), out);
index d19cec25b297727006c8ed41d58fa9eb81f9745b..5591d6d17579ef85dbbb235686d7ab706ada346c 100644 (file)
@@ -18,7 +18,7 @@
 
 #include "common/converter.h"
 #include "common/logger.h"
-#include "common/platform_exception.h"
+#include "common/extension.h"
 #include "common/task-queue.h"
 
 #include "bluetooth_adapter.h"
@@ -31,6 +31,7 @@ namespace extension {
 namespace bluetooth {
 
 using namespace common;
+using namespace common::tools;
 
 namespace {
 const std::string kId = "id";
@@ -240,39 +241,39 @@ void BluetoothHealthProfileHandler::RegisterSinkApp(const picojson::value& data,
     auto register_app = [data_type, name, this](const std::shared_ptr<picojson::value>& response) -> void {
         LoggerD("Entered");
 
-        try {
-            char* app_id = nullptr;
-            const int ret = bt_hdp_register_sink_app(data_type, &app_id);
+        PlatformResult platform_result = PlatformResult(ErrorCode::NO_ERROR);
+        char* app_id = nullptr;
+        const int ret = bt_hdp_register_sink_app(data_type, &app_id);
 
-            switch (ret) {
-            case BT_ERROR_NONE:
-            {
-                LoggerD("Registered app: %s", app_id);
+        switch (ret) {
+        case BT_ERROR_NONE:
+        {
+            LoggerD("Registered app: %s", app_id);
 
-                this->registered_health_apps_.insert(app_id);
+            this->registered_health_apps_.insert(app_id);
 
-                picojson::value result = picojson::value(picojson::object());
-                BluetoothHealthApplication::ToJson(data_type,
-                                                   name,
-                                                   app_id,
-                                                   &result.get<picojson::object>());
-                util::ReportSuccess(result, response->get<picojson::object>());
-            }
-                break;
+            picojson::value result = picojson::value(picojson::object());
+            BluetoothHealthApplication::ToJson(data_type,
+                                               name,
+                                               app_id,
+                                               &result.get<picojson::object>());
+            util::ReportSuccess(result, response->get<picojson::object>());
+            return;
+        }
 
-            case BT_ERROR_NOT_ENABLED:
-                LoggerE("Bluetooth device is turned off");
-                throw ServiceNotAvailableException("Bluetooth device is turned off");
-                break;
+        case BT_ERROR_NOT_ENABLED:
+            LoggerE("Bluetooth device is turned off");
+            platform_result = PlatformResult(
+                ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+            break;
 
-            default:
-                LoggerE("bt_hdp_register_sink_app() failed: %d", ret);
-                throw UnknownException("Unknown error");
-                break;
-            }
-        } catch (const PlatformException& e) {
-            util::ReportError(e, response->get<picojson::object>());
+        default:
+            LoggerE("bt_hdp_register_sink_app() failed: %d", ret);
+            platform_result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
+            break;
         }
+
+        ReportError(platform_result, &response->get<picojson::object>());
     };
 
     auto register_app_response = [callback_handle](const std::shared_ptr<picojson::value>& response) -> void {
@@ -300,35 +301,34 @@ void BluetoothHealthProfileHandler::ConnectToSource(const picojson::value& data,
 
     const auto callback_handle = util::GetAsyncCallbackHandle(data);
 
-    try {
-        const int ret = bt_hdp_connect_to_source(address.c_str(), app_id.c_str());
+    PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+    const int ret = bt_hdp_connect_to_source(address.c_str(), app_id.c_str());
 
-        switch (ret) {
-            case BT_ERROR_NONE: {
-                LoggerD("bt_hdp_connect_to_source() succeeded");
+    switch (ret) {
+        case BT_ERROR_NONE: {
+            LoggerD("bt_hdp_connect_to_source() succeeded");
 
-                connection_requests_.insert(std::make_pair(app_id, callback_handle));
-                break;
-            }
+            connection_requests_.insert(std::make_pair(app_id, callback_handle));
+            break;
+        }
 
-            case BT_ERROR_NOT_ENABLED:
-                throw ServiceNotAvailableException("Bluetooth device is turned off");
-                break;
+        case BT_ERROR_NOT_ENABLED:
+            result = PlatformResult(
+                ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+            break;
 
-            case BT_ERROR_INVALID_PARAMETER:
-            case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
-                throw InvalidValuesException("Invalid value");
-                break;
+        case BT_ERROR_INVALID_PARAMETER:
+        case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
+            result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+            break;
 
-            default:
-                throw UnknownException("Unknown error");
-                break;
-        }
-    } catch (const PlatformException& e) {
-        LoggerD("Exception: %s", e.message().c_str());
-        std::shared_ptr<picojson::value> response{new picojson::value(picojson::object())};
-        util::ReportError(e, response->get<picojson::object>());
-        util::AsyncResponse(callback_handle, response);
+        default:
+            result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+            break;
+    }
+
+    if (result.IsError()) {
+        util::AsyncResponse(callback_handle, result);
     }
 
     util::ReportSuccess(out);
@@ -341,38 +341,39 @@ void BluetoothHealthProfileHandler::UnregisterSinkAppAsync(const std::string& ap
     auto unregister_app = [app_id, this](const std::shared_ptr<picojson::value>& response) -> void {
         LoggerD("Entered");
 
+        PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
         auto iter = this->registered_health_apps_.find(app_id);
 
         if (iter != this->registered_health_apps_.end()) {
             LoggerD("Found registered Health Application: %s", app_id.c_str());
 
-            try {
-                const int ret = bt_hdp_unregister_sink_app(app_id.c_str());
-
-                switch(ret) {
-                case BT_ERROR_NONE:
-                    this->registered_health_apps_.erase(iter);
-                    break;
-
-                case BT_ERROR_NOT_ENABLED:
-                    LoggerE("Bluetooth device is turned off");
-                    throw ServiceNotAvailableException("Bluetooth device is turned off");
-                    break;
-
-                default:
-                    LoggerE("bt_hdp_unregister_sink_app() failed: %d", ret);
-                    throw UnknownException("Unknown error");
-                    break;
-                }
-            } catch (const PlatformException& e) {
-                util::ReportError(e, response->get<picojson::object>());
-                return;
+            const int ret = bt_hdp_unregister_sink_app(app_id.c_str());
+
+            switch(ret) {
+            case BT_ERROR_NONE:
+                this->registered_health_apps_.erase(iter);
+                break;
+
+            case BT_ERROR_NOT_ENABLED:
+                LoggerE("Bluetooth device is turned off");
+                result = PlatformResult(
+                    ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+                break;
+
+            default:
+                LoggerE("bt_hdp_unregister_sink_app() failed: %d", ret);
+                result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+                break;
             }
         } else {
             LoggerD("Already unregistered");
         }
 
-        util::ReportSuccess(response->get<picojson::object>());
+        if (result.IsSuccess()) {
+            ReportSuccess(response->get<picojson::object>());
+        } else {
+            ReportError(result, &response->get<picojson::object>());
+        }
     };
 
     auto unregister_app_response = [callback_handle](const std::shared_ptr<picojson::value>& response) -> void {
index 7925145fb3a69901ea3db003d4bd0b8e8f260fa5..ec0f219d4012035f0cd4b8deaf39c4e09a4b5f07 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "common/converter.h"
 #include "common/logger.h"
+#include "common/extension.h"
 
 #include "bluetooth_adapter.h"
 #include "bluetooth_device.h"
@@ -40,6 +41,7 @@ const int kBluetoothError = -1;
 }
 
 using namespace common;
+using namespace common::tools;
 
 void BluetoothSocket::WriteData(const picojson::value& data, picojson::object& out) {
     LoggerD("Enter");
@@ -60,7 +62,8 @@ void BluetoothSocket::WriteData(const picojson::value& data, picojson::object& o
 
     if (kBluetoothError == bt_socket_send_data(socket, data_ptr.get(), data_size)) {
         LoggerE("bt_socket_send_data() failed");
-        throw UnknownException("Unknown error");
+        ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+        return;
     }
 
     util::ReportSuccess(picojson::value(static_cast<double>(data_size)), out);
@@ -99,7 +102,8 @@ void BluetoothSocket::Close(const picojson::value& data, picojson::object& out)
 
     if (BT_ERROR_NONE != bt_socket_disconnect_rfcomm(socket)) {
         LoggerE("bt_socket_disconnect_rfcomm() failed");
-        throw UnknownException("Unknown error");
+        ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+        return;
     }
 
     util::ReportSuccess(out);