Repository: ignite Updated Branches: refs/heads/ignite-2004 94e301d8c -> 09b56444d
IGNITE-2902: CPP: IgniteError is now extends std::exception. This closes #582. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7f9ee2d5 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7f9ee2d5 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7f9ee2d5 Branch: refs/heads/ignite-2004 Commit: 7f9ee2d599b8a531f6b7046a418fd7f947abf8d0 Parents: 732abda Author: isapego <[email protected]> Authored: Tue Mar 29 13:58:36 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Tue Mar 29 13:58:36 2016 +0300 ---------------------------------------------------------------------- modules/platforms/cpp/core-test/Makefile.am | 1 + .../cpp/core-test/project/vs/core-test.vcxproj | 1 + .../project/vs/core-test.vcxproj.filters | 3 ++ .../cpp/core-test/src/ignite_error_test.cpp | 45 ++++++++++++++++++++ .../cpp/core/include/ignite/ignite_error.h | 15 +++++-- modules/platforms/cpp/core/src/ignite_error.cpp | 7 ++- 6 files changed, 68 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/7f9ee2d5/modules/platforms/cpp/core-test/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/Makefile.am b/modules/platforms/cpp/core-test/Makefile.am index 531fee0..55b3b98 100644 --- a/modules/platforms/cpp/core-test/Makefile.am +++ b/modules/platforms/cpp/core-test/Makefile.am @@ -31,6 +31,7 @@ ignite_tests_SOURCES = src/cache_test.cpp \ src/ignition_test.cpp \ src/interop_memory_test.cpp \ src/handle_registry_test.cpp \ + src/ignite_error_test.cpp \ src/binary_test_defs.cpp \ src/binary_reader_writer_raw_test.cpp \ src/binary_reader_writer_test.cpp \ http://git-wip-us.apache.org/repos/asf/ignite/blob/7f9ee2d5/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj index d98d202..9e3d816 100644 --- a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj +++ b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj @@ -33,6 +33,7 @@ <ItemGroup> <ClCompile Include="..\..\src\cache_test.cpp" /> <ClCompile Include="..\..\src\concurrent_test.cpp" /> + <ClCompile Include="..\..\src\ignite_error_test.cpp" /> <ClCompile Include="..\..\src\ignition_test.cpp" /> <ClCompile Include="..\..\src\handle_registry_test.cpp" /> <ClCompile Include="..\..\src\binary_reader_writer_raw_test.cpp" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/7f9ee2d5/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters index 15b9c40..ec7bab5 100644 --- a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters +++ b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters @@ -37,6 +37,9 @@ <ClCompile Include="..\..\src\interop_memory_test.cpp"> <Filter>Code</Filter> </ClCompile> + <ClCompile Include="..\..\src\ignite_error_test.cpp"> + <Filter>Code</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\include\teamcity_messages.h"> http://git-wip-us.apache.org/repos/asf/ignite/blob/7f9ee2d5/modules/platforms/cpp/core-test/src/ignite_error_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/ignite_error_test.cpp b/modules/platforms/cpp/core-test/src/ignite_error_test.cpp new file mode 100644 index 0000000..c9e3043 --- /dev/null +++ b/modules/platforms/cpp/core-test/src/ignite_error_test.cpp @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _MSC_VER + #define BOOST_TEST_DYN_LINK +#endif + +#include <boost/test/unit_test.hpp> + +#include "ignite/ignite_error.h" + +using namespace ignite; +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(IgniteErrorTestSuite) + +BOOST_AUTO_TEST_CASE(TestIgniteErrorDerivesStdException) +{ + const std::string testMsg = "Lorem ipsum dolor sit amet"; + + try + { + throw IgniteError(IgniteError::IGNITE_ERR_GENERIC, testMsg.c_str()); + } + catch (std::exception& e) + { + BOOST_REQUIRE_EQUAL(testMsg, std::string(e.what())); + } +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/7f9ee2d5/modules/platforms/cpp/core/include/ignite/ignite_error.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/ignite_error.h b/modules/platforms/cpp/core/include/ignite/ignite_error.h index 3b192b1..4097a62 100644 --- a/modules/platforms/cpp/core/include/ignite/ignite_error.h +++ b/modules/platforms/cpp/core/include/ignite/ignite_error.h @@ -23,9 +23,11 @@ #ifndef _IGNITE_ERROR #define _IGNITE_ERROR -#include <sstream> #include <stdint.h> +#include <exception> +#include <sstream> + #include <ignite/common/common.h> #define IGNITE_ERROR_1(code, part1) { \ @@ -75,7 +77,7 @@ namespace ignite /** * Ignite error information. */ - class IGNITE_IMPORT_EXPORT IgniteError + class IGNITE_IMPORT_EXPORT IgniteError : public std::exception { public: /** Success. */ @@ -243,7 +245,14 @@ namespace ignite * @return Error message. */ const char* GetText() const; - + + /** + * Get error message. Synonim for GetText(). + * + * @return Error message. + */ + virtual const char* what() const; + /** * Set error. * http://git-wip-us.apache.org/repos/asf/ignite/blob/7f9ee2d5/modules/platforms/cpp/core/src/ignite_error.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/ignite_error.cpp b/modules/platforms/cpp/core/src/ignite_error.cpp index 1545631..ad30e46 100644 --- a/modules/platforms/cpp/core/src/ignite_error.cpp +++ b/modules/platforms/cpp/core/src/ignite_error.cpp @@ -90,7 +90,12 @@ namespace ignite else return "No additional information available."; } - + + const char* IgniteError::what() const + { + return GetText(); + } + void IgniteError::SetError(const int jniCode, const char* jniCls, const char* jniMsg, IgniteError* err) { if (jniCode == IGNITE_JNI_ERR_SUCCESS)
