clean up exceptions

This commit is contained in:
Thomas Fussell 2016-07-21 23:04:36 -04:00
parent 1859761775
commit c009278c60
30 changed files with 260 additions and 641 deletions

View File

@ -44,6 +44,26 @@ enum class XLNT_CLASS target_mode
internal
};
/// <summary>
/// All package relationships must be one of these defined types.
/// </summary>
enum class relationship_type
{
invalid,
hyperlink,
drawing,
worksheet,
chartsheet,
shared_strings,
styles,
theme,
extended_properties,
core_properties,
office_document,
custom_xml,
thumbnail
};
/// <summary>
/// Represents an association between a source Package or part, and a target object which can be a part or external
/// resource.
@ -51,22 +71,7 @@ enum class XLNT_CLASS target_mode
class XLNT_CLASS relationship
{
public:
enum class type
{
invalid,
hyperlink,
drawing,
worksheet,
chartsheet,
shared_strings,
styles,
theme,
extended_properties,
core_properties,
office_document,
custom_xml,
thumbnail
};
using type = relationship_type;
static type type_from_string(const std::string &type_string);

View File

@ -1,41 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// Error when an attribute value is invalid.
/// </summary>
class XLNT_CLASS attribute_error : public std::runtime_error
{
public:
attribute_error();
};
} // namespace xlnt

View File

@ -1,44 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <string>
#include <xlnt/xlnt_config.hpp>
#include <xlnt/cell/index_types.hpp>
namespace xlnt {
/// <summary>
/// Error for converting between numeric and A1-style cell references.
/// </summary>
class XLNT_CLASS cell_coordinates_exception : public std::runtime_error
{
public:
cell_coordinates_exception(column_t column, row_t row);
cell_coordinates_exception(const std::string &coord_string);
};
} // namespace xlnt

View File

@ -1,41 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// Error for bad column names in A1-style cell references.
/// </summary>
class XLNT_CLASS column_string_index_exception : public std::runtime_error
{
public:
column_string_index_exception();
};
} // namespace xlnt

View File

@ -1,41 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// Error for any data type inconsistencies.
/// </summary>
class XLNT_CLASS data_type_exception : public std::runtime_error
{
public:
data_type_exception();
};
} // namespace xlnt

View File

@ -23,18 +23,145 @@
// @author: see AUTHORS file
#pragma once
// An shortcut for including all possible exceptions in xlnt.
#include <cstdint>
#include <stdexcept>
#include <xlnt/utils/attribute_error.hpp>
#include <xlnt/utils/cell_coordinates_exception.hpp>
#include <xlnt/utils/column_string_index_exception.hpp>
#include <xlnt/utils/data_type_exception.hpp>
#include <xlnt/utils/illegal_character_error.hpp>
#include <xlnt/utils/invalid_file_exception.hpp>
#include <xlnt/utils/key_error.hpp>
#include <xlnt/utils/missing_number_format.hpp>
#include <xlnt/utils/named_range_exception.hpp>
#include <xlnt/utils/read_only_workbook_exception.hpp>
#include <xlnt/utils/sheet_title_exception.hpp>
#include <xlnt/utils/unicode_decode_error.hpp>
#include <xlnt/utils/value_error.hpp>
#include <xlnt/xlnt_config.hpp>
#include <xlnt/cell/index_types.hpp>
namespace xlnt {
/// <summary>
/// Parent type of all custom exceptions thrown in this library.
/// </summary>
class XLNT_CLASS error : public std::runtime_error
{
public:
error();
error(const std::string &message);
void set_message(const std::string &message);
private:
std::string message_;
};
class XLNT_CLASS value_error : public error
{
public:
value_error();
};
/// <summary>
/// Error for string encoding not matching workbook encoding
/// </summary>
class XLNT_CLASS unicode_decode_error : public error
{
public:
unicode_decode_error();
unicode_decode_error(char c);
unicode_decode_error(std::uint8_t b);
};
/// <summary>
/// Error for bad sheet names.
/// </summary>
class XLNT_CLASS sheet_title_error : public error
{
public:
sheet_title_error(const std::string &title);
};
/// <summary>
/// Error for trying to modify a read-only workbook.
/// </summary>
class XLNT_CLASS read_only_workbook_error : public error
{
public:
read_only_workbook_error();
};
/// <summary>
/// Error for incorrectly formatted named ranges.
/// </summary>
class XLNT_CLASS named_range_error : public error
{
public:
named_range_error();
};
/// <summary>
/// Error when a referenced number format is not in the stylesheet.
/// </summary>
class XLNT_CLASS missing_number_format : public error
{
public:
missing_number_format();
};
/// <summary>
/// Error for trying to open a non-OOXML file.
/// </summary>
class XLNT_CLASS invalid_file_error : public error
{
public:
invalid_file_error(const std::string &filename);
};
/// <summary>
/// The data submitted which cannot be used directly in Excel files. It
/// must be removed or escaped.
/// </summary>
class XLNT_CLASS illegal_character_error : public error
{
public:
illegal_character_error(char c);
};
/// <summary>
/// Error for any data type inconsistencies.
/// </summary>
class XLNT_CLASS data_type_error : public error
{
public:
data_type_error();
};
/// <summary>
/// Error for bad column names in A1-style cell references.
/// </summary>
class XLNT_CLASS column_string_index_error : public error
{
public:
column_string_index_error();
};
/// <summary>
/// Error for converting between numeric and A1-style cell references.
/// </summary>
class XLNT_CLASS cell_coordinates_error : public error
{
public:
cell_coordinates_error(column_t column, row_t row);
cell_coordinates_error(const std::string &coord_string);
};
/// <summary>
/// Error when an attribute value is invalid.
/// </summary>
class XLNT_CLASS attribute_error : public error
{
public:
attribute_error();
};
/// <summary>
/// key_error
/// </summary>
class XLNT_CLASS key_error : public error
{
public:
key_error();
};
} // namespace xlnt

View File

@ -1,42 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// The data submitted which cannot be used directly in Excel files. It
/// must be removed or escaped.
/// </summary>
class XLNT_CLASS illegal_character_error : public std::runtime_error
{
public:
illegal_character_error(char c);
};
} // namespace xlnt

View File

@ -1,42 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <string>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// Error for trying to open a non-OOXML file.
/// </summary>
class XLNT_CLASS invalid_file_exception : public std::runtime_error
{
public:
invalid_file_exception(const std::string &filename);
};
} // namespace xlnt

View File

@ -1,41 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// key_error
/// </summary>
class XLNT_CLASS key_error : public std::runtime_error
{
public:
key_error();
};
} // namespace xlnt

View File

@ -1,41 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// Error when a referenced number format is not in the stylesheet.
/// </summary>
class XLNT_CLASS missing_number_format : public std::runtime_error
{
public:
missing_number_format();
};
} // namespace xlnt

View File

@ -1,41 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// Error for incorrectly formatted named ranges.
/// </summary>
class XLNT_CLASS named_range_exception : public std::runtime_error
{
public:
named_range_exception();
};
} // namespace xlnt

View File

@ -1,41 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// Error for trying to modify a read-only workbook.
/// </summary>
class XLNT_CLASS read_only_workbook_exception : public std::runtime_error
{
public:
read_only_workbook_exception();
};
} // namespace xlnt

View File

@ -1,42 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <string>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// Error for bad sheet names.
/// </summary>
class XLNT_CLASS sheet_title_exception : public std::runtime_error
{
public:
sheet_title_exception(const std::string &title);
};
} // namespace xlnt

View File

@ -1,44 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <cstdint>
#include <stdexcept>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
/// <summary>
/// Error for string encoding not matching workbook encoding
/// </summary>
class XLNT_CLASS unicode_decode_error : public std::runtime_error
{
public:
unicode_decode_error();
unicode_decode_error(char c);
unicode_decode_error(std::uint8_t b);
};
} // namespace xlnt

View File

@ -1,39 +0,0 @@
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#pragma once
#include <stdexcept>
#include <string>
#include <xlnt/xlnt_config.hpp>
namespace xlnt {
class XLNT_CLASS value_error : public std::runtime_error
{
public:
value_error();
};
} // namespace xlnt

View File

@ -32,7 +32,6 @@
#include <vector>
#include <xlnt/xlnt_config.hpp>
#include <xlnt/packaging/relationship.hpp>
namespace xlnt {
@ -64,6 +63,8 @@ class worksheet;
class worksheet_iterator;
class zip_file;
enum class relationship_type;
namespace detail {
struct workbook_impl;
} // namespace detail
@ -259,11 +260,11 @@ public:
// relationships
void create_relationship(const std::string &id, const std::string &target, relationship::type type);
void create_relationship(const std::string &id, const std::string &target, relationship_type type);
relationship get_relationship(const std::string &id) const;
const std::vector<relationship> &get_relationships() const;
void create_root_relationship(const std::string &id, const std::string &target, relationship::type type);
void create_root_relationship(const std::string &id, const std::string &target, relationship_type type);
const std::vector<relationship> &get_root_relationships() const;
// shared strings

View File

@ -461,7 +461,7 @@ void cell::set_hyperlink(const std::string &hyperlink)
{
if (hyperlink.length() == 0 || std::find(hyperlink.begin(), hyperlink.end(), ':') == hyperlink.end())
{
throw data_type_exception();
throw data_type_error();
}
d_->has_hyperlink_ = true;
@ -477,7 +477,7 @@ void cell::set_formula(const std::string &formula)
{
if (formula.length() == 0)
{
throw data_type_exception();
throw data_type_error();
}
if (formula[0] == '=')
@ -499,7 +499,7 @@ std::string cell::get_formula() const
{
if (d_->formula_.empty())
{
throw data_type_exception();
throw data_type_error();
}
return d_->formula_;
@ -544,7 +544,7 @@ void cell::set_error(const std::string &error)
{
if (error.length() == 0 || error[0] != '#')
{
throw data_type_exception();
throw data_type_error();
}
d_->value_text_.set_plain_string(error);

View File

@ -76,7 +76,7 @@ cell_reference::cell_reference(column_t column_index, row_t row)
if (!(row_ <= constants::MaxRow()) || !(column_ <= constants::MaxColumn()))
{
throw cell_coordinates_exception(column_, row_);
throw cell_coordinates_error(column_, row_);
}
}
@ -134,7 +134,7 @@ std::pair<std::string, row_t> cell_reference::split_reference(const std::string
}
else
{
throw cell_coordinates_exception(reference_string);
throw cell_coordinates_error(reference_string);
}
}
else if (character == '$')
@ -159,7 +159,7 @@ std::pair<std::string, row_t> cell_reference::split_reference(const std::string
}
else if (!std::isdigit(character, std::locale::classic()))
{
throw cell_coordinates_exception(reference_string);
throw cell_coordinates_error(reference_string);
}
}
}
@ -168,7 +168,7 @@ std::pair<std::string, row_t> cell_reference::split_reference(const std::string
if (row_string.length() == 0)
{
throw cell_coordinates_exception(reference_string);
throw cell_coordinates_error(reference_string);
}
if (column_string[0] == '$')

View File

@ -23,18 +23,17 @@
// @author: see AUTHORS file
#include <locale>
#include <detail/constants.hpp>
#include <xlnt/cell/index_types.hpp>
#include <xlnt/utils/exceptions.hpp>
#include <detail/constants.hpp>
namespace xlnt {
column_t::index_t column_t::column_index_from_string(const std::string &column_string)
{
if (column_string.length() > 3 || column_string.empty())
{
throw column_string_index_exception();
throw column_string_index_error();
}
column_t::index_t column_index = 0;
@ -44,7 +43,7 @@ column_t::index_t column_t::column_index_from_string(const std::string &column_s
{
if (!std::isalpha(column_string[static_cast<std::size_t>(i)], std::locale::classic()))
{
throw column_string_index_exception();
throw column_string_index_error();
}
auto char_index = std::toupper(column_string[static_cast<std::size_t>(i)], std::locale::classic()) - 'A';
@ -67,7 +66,7 @@ std::string column_t::column_string_from_index(column_t::index_t column_index)
if (column_index < constants::MinColumn() || column_index > constants::MaxColumn())
{
// auto msg = "Column index out of bounds: " + std::to_string(column_index);
throw column_string_index_exception();
throw column_string_index_error();
}
int temp = static_cast<int>(column_index);

View File

@ -604,12 +604,12 @@ public:
TS_ASSERT_DIFFERS(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 1)));
TS_ASSERT_EQUALS(hash(xlnt::cell_reference("A2")), hash(xlnt::cell_reference(1, 2)));
TS_ASSERT_THROWS(xlnt::cell_reference(10000000, 10000000), xlnt::cell_coordinates_exception);
TS_ASSERT_THROWS(xlnt::cell_reference(10000000, 10000000), xlnt::cell_coordinates_error);
TS_ASSERT_EQUALS((xlnt::cell_reference("A1"), xlnt::cell_reference("B2")), xlnt::range_reference("A1:B2"));
TS_ASSERT_THROWS(xlnt::cell_reference("A1A"), xlnt::cell_coordinates_exception);
TS_ASSERT_THROWS(xlnt::cell_reference("A"), xlnt::cell_coordinates_exception);
TS_ASSERT_THROWS(xlnt::cell_reference("A1A"), xlnt::cell_coordinates_error);
TS_ASSERT_THROWS(xlnt::cell_reference("A"), xlnt::cell_coordinates_error);
auto ref = xlnt::cell_reference("$B$7");
TS_ASSERT(ref.row_absolute());

View File

@ -10,15 +10,15 @@ class test_index_types : public CxxTest::TestSuite
public:
void test_bad_string()
{
TS_ASSERT_THROWS(xlnt::column_t::column_index_from_string(""), xlnt::column_string_index_exception);
TS_ASSERT_THROWS(xlnt::column_t::column_index_from_string("ABCD"), xlnt::column_string_index_exception);
TS_ASSERT_THROWS(xlnt::column_t::column_index_from_string("123"), xlnt::column_string_index_exception);
TS_ASSERT_THROWS(xlnt::column_t::column_index_from_string(""), xlnt::column_string_index_error);
TS_ASSERT_THROWS(xlnt::column_t::column_index_from_string("ABCD"), xlnt::column_string_index_error);
TS_ASSERT_THROWS(xlnt::column_t::column_index_from_string("123"), xlnt::column_string_index_error);
}
void test_bad_column()
{
TS_ASSERT_THROWS(xlnt::column_t::column_string_from_index(0), xlnt::column_string_index_exception);
TS_ASSERT_THROWS(xlnt::column_t::column_string_from_index(10000000), xlnt::column_string_index_exception);
TS_ASSERT_THROWS(xlnt::column_t::column_string_from_index(0), xlnt::column_string_index_error);
TS_ASSERT_THROWS(xlnt::column_t::column_string_from_index(10000000), xlnt::column_string_index_error);
}
void test_column_operators()

View File

@ -73,7 +73,7 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
if(!archive.has_file(xlnt::constants::ArcContentTypes()))
{
throw xlnt::invalid_file_exception("missing [Content Types].xml");
throw xlnt::invalid_file_error("missing [Content Types].xml");
}
xlnt::manifest_serializer ms(wb.get_manifest());
@ -83,7 +83,7 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl
if (ms.determine_document_type() != "excel")
{
throw xlnt::invalid_file_exception("package is not an OOXML SpreadsheetML");
throw xlnt::invalid_file_error("package is not an OOXML SpreadsheetML");
}
wb.clear();
@ -222,7 +222,7 @@ bool excel_serializer::load_workbook(const std::string &filename, bool guess_typ
}
catch (std::runtime_error)
{
throw invalid_file_exception(filename);
throw invalid_file_error(filename);
}
return ::load_workbook(archive_, guess_types, data_only, workbook_, get_stylesheet());

View File

@ -21,78 +21,94 @@
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#include <xlnt/utils/exceptions.hpp>
namespace xlnt {
sheet_title_exception::sheet_title_exception(const std::string &title)
: std::runtime_error(std::string("bad worksheet title: ") + title)
error::error() : std::runtime_error("xlnt::error")
{
}
column_string_index_exception::column_string_index_exception()
: std::runtime_error("column string index exception")
error::error(const std::string &message)
: std::runtime_error("xlnt::error : " + message)
{
set_message(message);
}
void error::set_message(const std::string &message)
{
message_ = message;
}
sheet_title_error::sheet_title_error(const std::string &title)
: error(std::string("bad worksheet title: ") + title)
{
}
data_type_exception::data_type_exception()
: std::runtime_error("data type exception")
column_string_index_error::column_string_index_error()
: error("column string index error")
{
}
attribute_error::attribute_error()
: std::runtime_error("attribute error")
data_type_error::data_type_error()
: error("data type error")
{
}
named_range_exception::named_range_exception()
: std::runtime_error("named range not found or not owned by this worksheet")
named_range_error::named_range_error()
: error("named range not found or not owned by this worksheet")
{
}
invalid_file_exception::invalid_file_exception(const std::string &filename)
: std::runtime_error(std::string("couldn't open file: (") + filename + ")")
invalid_file_error::invalid_file_error(const std::string &filename)
: error(std::string("couldn't open file: (") + filename + ")")
{
}
cell_coordinates_exception::cell_coordinates_exception(column_t column, row_t row)
: std::runtime_error(std::string("bad cell coordinates: (") + std::to_string(column.index) + ", " + std::to_string(row) +
cell_coordinates_error::cell_coordinates_error(column_t column, row_t row)
: error(std::string("bad cell coordinates: (") + std::to_string(column.index) + ", " + std::to_string(row) +
")")
{
}
cell_coordinates_exception::cell_coordinates_exception(const std::string &coord_string)
: std::runtime_error(std::string("bad cell coordinates: (") + (coord_string.empty() ? "<empty>" : coord_string) + ")")
cell_coordinates_error::cell_coordinates_error(const std::string &coord_string)
: error(std::string("bad cell coordinates: (") + (coord_string.empty() ? "<empty>" : coord_string) + ")")
{
}
illegal_character_error::illegal_character_error(char c)
: std::runtime_error(std::string("illegal character: (") + std::to_string(static_cast<unsigned char>(c)) + ")")
: error(std::string("illegal character: (") + std::to_string(static_cast<unsigned char>(c)) + ")")
{
}
unicode_decode_error::unicode_decode_error()
: std::runtime_error("unicode decode error")
: error("unicode decode error")
{
}
unicode_decode_error::unicode_decode_error(char)
: std::runtime_error("unicode decode error")
: error("unicode decode error")
{
}
value_error::value_error()
: std::runtime_error("value error")
: error("value error")
{
}
read_only_workbook_error::read_only_workbook_error()
: error("workbook is read-only")
{
}
attribute_error::attribute_error()
: error("bad attribute")
{
}
key_error::key_error()
: std::runtime_error("key error")
{
}
read_only_workbook_exception::read_only_workbook_exception()
: std::runtime_error("workbook is read-only")
: error("key not found in container")
{
}

View File

@ -21,7 +21,6 @@
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#include <xlnt/utils/utf8string.hpp>
#include <xlnt/utils/unicode_decode_error.hpp>
namespace xlnt {

View File

@ -86,7 +86,7 @@ std::vector<std::pair<std::string, std::string>> split_named_range(const std::st
{
xlnt::range_reference ref(split[1]);
}
catch (xlnt::cell_coordinates_exception)
catch (xlnt::cell_coordinates_error)
{
split[1] = "";
}

View File

@ -68,7 +68,7 @@ public:
xlnt::workbook wb;
xlnt::excel_serializer serializer(wb);
TS_ASSERT_THROWS(serializer.load_workbook(path), xlnt::invalid_file_exception);
TS_ASSERT_THROWS(serializer.load_workbook(path), xlnt::invalid_file_error);
}
void test_read_empty_archive()
@ -78,7 +78,7 @@ public:
xlnt::workbook wb;
xlnt::excel_serializer serializer(wb);
TS_ASSERT_THROWS(serializer.load_workbook(path), xlnt::invalid_file_exception);
TS_ASSERT_THROWS(serializer.load_workbook(path), xlnt::invalid_file_error);
}
void test_read_workbook_with_no_properties()
@ -471,7 +471,7 @@ public:
xlnt::workbook wb;
xlnt::excel_serializer serializer(wb);
TS_ASSERT_THROWS(serializer.load_workbook(path), xlnt::invalid_file_exception);
TS_ASSERT_THROWS(serializer.load_workbook(path), xlnt::invalid_file_error);
}
void test_bad_formats_xls()
@ -481,7 +481,7 @@ public:
xlnt::workbook wb;
xlnt::excel_serializer serializer(wb);
TS_ASSERT_THROWS(serializer.load_workbook(path), xlnt::invalid_file_exception);
TS_ASSERT_THROWS(serializer.load_workbook(path), xlnt::invalid_file_error);
}
void test_bad_formats_no()
@ -491,7 +491,7 @@ public:
xlnt::workbook wb;
xlnt::excel_serializer serializer(wb);
TS_ASSERT_THROWS(serializer.load_workbook(path), xlnt::invalid_file_exception);
TS_ASSERT_THROWS(serializer.load_workbook(path), xlnt::invalid_file_error);
}

View File

@ -82,7 +82,7 @@ public:
{
xlnt::workbook wb;
wb.set_read_only(true);
TS_ASSERT_THROWS(wb.create_sheet(), xlnt::read_only_workbook_exception);
TS_ASSERT_THROWS(wb.create_sheet(), xlnt::read_only_workbook_error);
}
void test_remove_sheet()
@ -91,7 +91,7 @@ public:
auto new_sheet = wb.create_sheet(0);
new_sheet.set_title("removed");
wb.remove_sheet(new_sheet);
TS_ASSERT_EQUALS(wb.get_sheet_by_name("removed"), nullptr);
TS_ASSERT(!wb.contains("removed"));
TS_ASSERT_THROWS(wb.remove_sheet(wb2.get_active_sheet()), std::runtime_error);
}

View File

@ -103,12 +103,20 @@ const worksheet workbook::get_sheet_by_name(const std::string &name) const
}
}
return worksheet();
throw key_error();
}
worksheet workbook::get_sheet_by_name(const std::string &name)
{
return worksheet(static_cast<const workbook*>(this)->get_sheet_by_name(name));
for (auto &impl : d_->worksheets_)
{
if (impl.title_ == name)
{
return worksheet(&impl);
}
}
throw key_error();
}
worksheet workbook::get_sheet_by_index(std::size_t index)
@ -140,12 +148,12 @@ bool workbook::has_named_range(const std::string &name) const
worksheet workbook::create_sheet()
{
if(get_read_only()) throw xlnt::read_only_workbook_exception();
if(get_read_only()) throw xlnt::read_only_workbook_error();
std::string title = "Sheet";
int index = 0;
while (get_sheet_by_name(title) != nullptr)
while (contains(title))
{
title = "Sheet" + std::to_string(++index);
}
@ -368,14 +376,14 @@ worksheet workbook::create_sheet(const std::string &title)
{
if (title.length() > 31)
{
throw sheet_title_exception(title);
throw sheet_title_error(title);
}
if (std::find_if(title.begin(), title.end(), [](char c) {
return c == '*' || c == ':' || c == '/' || c == '\\' || c == '?' || c == '[' || c == ']';
}) != title.end())
{
throw sheet_title_exception(title);
throw sheet_title_error(title);
}
std::string unique_title = title;
@ -445,12 +453,16 @@ std::vector<std::string> workbook::get_sheet_names() const
worksheet workbook::operator[](const std::string &name)
{
if(!contains(name)) throw xlnt::key_error();
return get_sheet_by_name(name);
}
worksheet workbook::operator[](std::size_t index)
{
if (index > d_->worksheets_.size())
{
throw key_error();
}
return worksheet(&d_->worksheets_[index]);
}

View File

@ -217,7 +217,7 @@ public:
auto ws1 = wb[0];
auto ws2 = wb[1];
wb.create_named_range("wrong_sheet_range", ws1, "C5");
TS_ASSERT_THROWS(ws2.get_named_range("wrong_sheet_range"), xlnt::named_range_exception);
TS_ASSERT_THROWS(ws2.get_named_range("wrong_sheet_range"), xlnt::named_range_error);
}
void test_remove_named_range_bad()

View File

@ -327,7 +327,7 @@ range worksheet::get_named_range(const std::string &name)
if (!has_named_range(name))
{
throw named_range_exception();
throw named_range_error();
}
return get_range(d_->named_ranges_[name].get_targets()[0].second);