Commit 5efa354f authored by Pavel Doležal's avatar Pavel Doležal

Merge branch 'fix_exceptions' into 'master'

Fix exceptions

See merge request !22
parents 9749cf40 067cdce8
Pipeline #67130 passed with stage
in 3 minutes
......@@ -13,6 +13,7 @@
#include <string.h>
#include <stdlib.h>
#include <istream>
#include <iostream>
#include <sys/socket.h>
#include "format_specification.h"
......@@ -61,8 +62,13 @@ namespace CDNS {
* if any output is currently open
*/
~CdnsExporter() {
if (m_blocks_written > 0)
m_encoder.write_break();
try {
if (m_blocks_written > 0)
m_encoder.write_break();
}
catch (std::exception& e) {
std::cerr << "Couldn't write end break to output: " << e.what() << std::endl;
}
}
/** Delete [move] copy constructors and assignment operators */
......@@ -125,12 +131,16 @@ namespace CDNS {
/**
* @brief Write the given C-DNS block to output
* @param block C-DNS block to output
* @throw std::exception if writing Block to output fails.
* User should try to rotate output after this exception is thrown.
* @return Number of uncompressed bytes written
*/
std::size_t write_block(CdnsBlock& block);
/**
* @brief Write the internally buffered C-DNS block to output
* @throw std::exception if writing Block to output fails.
* User should try to rotate output after this exception is thrown.
* @return Number of uncompressed bytes written
*/
std::size_t write_block() {
......
......@@ -273,14 +273,9 @@ std::size_t CDNS::CdnsEncoder::write(int64_t value)
void CDNS::CdnsEncoder::flush_buffer()
{
if (m_p != m_buffer) {
try {
m_cos->write(reinterpret_cast<const char*>(m_buffer), m_p - m_buffer);
m_p = m_buffer;
m_avail = BUFFER_SIZE;
}
catch (CborOutputException& e) {
std::cerr << e.what() << std::endl;
}
m_cos->write(reinterpret_cast<const char*>(m_buffer), m_p - m_buffer);
m_p = m_buffer;
m_avail = BUFFER_SIZE;
}
}
......
......@@ -67,7 +67,13 @@ namespace CDNS {
* @brief Destroy the CdnsEncoder object and properly close the C-DNS output
*/
~CdnsEncoder() {
flush_buffer();
try {
flush_buffer();
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
if(m_cos)
delete m_cos;
}
......
......@@ -11,6 +11,7 @@
#define ZLIB_CONST
#include <string>
#include <iostream>
#include <fstream>
#include <cstdint>
#include <boost/any.hpp>
......@@ -175,11 +176,16 @@ namespace CDNS {
* @brief Close the opened output file with given name
*/
void close() override {
if (m_out.is_open()) {
m_out.flush();
m_out.close();
if (std::rename((m_value + m_extension + ".part").c_str(), (m_value + m_extension).c_str()))
throw CborOutputException("Couldn't rename the output file!");
try {
if (m_out.is_open()) {
m_out.flush();
m_out.close();
if (std::rename((m_value + m_extension + ".part").c_str(), (m_value + m_extension).c_str()))
std::cerr << "Couldn't rename the output file!" << std::endl;
}
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment