Remove jexception, leave ase_exception only.

This commit is contained in:
David Capello 2010-09-18 00:12:53 -03:00
parent c821cd3924
commit 99adf98c0f
8 changed files with 51 additions and 169 deletions

View File

@ -171,7 +171,6 @@ add_library(aseprite-library
jinete/jcustom_label.cpp
jinete/jdraw.cpp
jinete/jentry.cpp
jinete/jexception.cpp
jinete/jfont.cpp
jinete/jfontbmp.cpp
jinete/jgrid.cpp

View File

@ -23,6 +23,7 @@
#include "ase_exception.h"
#include "console.h"
#include "tinyxml.h"
ase_exception::ase_exception(const char* msg, ...) throw()
{
@ -46,8 +47,42 @@ ase_exception::ase_exception(const char* msg, ...) throw()
}
}
ase_exception::ase_exception(const std::string& msg) throw()
{
try {
m_msg = msg;
}
catch (...) {
// no throw
}
}
ase_exception::ase_exception(TiXmlDocument* doc) throw()
{
try {
char buf[1024];
usprintf(buf, "Error in XML file '%s' (line %d, column %d)\nError %d: %s",
doc->Value(), doc->ErrorRow(), doc->ErrorCol(),
doc->ErrorId(), doc->ErrorDesc());
m_msg = buf;
}
catch (...) {
// no throw
}
}
ase_exception::~ase_exception() throw()
{
}
void ase_exception::show()
{
Console console;
console.printf("A problem has occurred.\n\nDetails:\n%s", what());
}
const char* ase_exception::what() const throw()
{
return m_msg.c_str();
}

View File

@ -19,20 +19,26 @@
#ifndef ASE_EXCEPTION_H_INCLUDED
#define ASE_EXCEPTION_H_INCLUDED
#include "jinete/jexception.h"
#include <exception>
#include <string>
#include "jinete/jbase.h"
class ase_exception : public jexception
class TiXmlDocument;
class ase_exception : public std::exception
{
public:
ase_exception() throw() { }
ase_exception() throw();
ase_exception(const char* msg, ...) throw();
ase_exception(const std::string& msg) throw() : jexception(msg) { }
ase_exception(TiXmlDocument* doc) throw() : jexception(doc) { }
~ase_exception() throw() { }
ase_exception(const std::string& msg) throw();
ase_exception(TiXmlDocument* doc) throw();
virtual ~ase_exception() throw();
virtual void show();
const char* what() const throw();
private:
std::string m_msg;
};
#endif

View File

@ -1,99 +0,0 @@
/* Jinete - a GUI library
* Copyright (C) 2003-2010 David Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of the author nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include <allegro.h>
#include <stdio.h>
#include "jinete/jexception.h"
#include "tinyxml.h"
jexception::jexception(const char* msg, ...) throw()
{
try {
if (!ustrchr(msg, '%')) {
m_msg = msg;
}
else {
va_list ap;
va_start(ap, msg);
char buf[1024]; // TODO warning buffer overflow
uvsprintf(buf, msg, ap);
m_msg = buf;
va_end(ap);
}
}
catch (...) {
// no throw
}
}
jexception::jexception(const std::string& msg) throw()
{
try {
m_msg = msg;
}
catch (...) {
// no throw
}
}
jexception::jexception(TiXmlDocument* doc) throw()
{
try {
char buf[1024];
usprintf(buf, "Error in XML file '%s' (line %d, column %d)\nError %d: %s",
doc->Value(), doc->ErrorRow(), doc->ErrorCol(),
doc->ErrorId(), doc->ErrorDesc());
m_msg = buf;
}
catch (...) {
// no throw
}
}
jexception::~jexception() throw()
{
}
void jexception::show()
{
allegro_message("A problem has occurred.\n\nDetails:\n%s", what());
}
const char* jexception::what() const throw()
{
return m_msg.c_str();
}

View File

@ -1,59 +0,0 @@
/* Jinete - a GUI library
* Copyright (C) 2003-2010 David Capello.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of the author nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef JINETE_JEXCEPTION_H_INCLUDED
#define JINETE_JEXCEPTION_H_INCLUDED
#include <exception>
#include <string>
#include "jinete/jbase.h"
class TiXmlDocument;
class jexception : public std::exception
{
protected:
std::string m_msg;
public:
jexception() throw() { }
jexception(const char* msg, ...) throw();
jexception(const std::string& msg) throw();
jexception(TiXmlDocument* doc) throw();
virtual ~jexception() throw();
virtual void show();
const char* what() const throw();
};
#endif

View File

@ -42,7 +42,6 @@
#include "jinete/jcustom_label.h"
#include "jinete/jdraw.h"
#include "jinete/jentry.h"
#include "jinete/jexception.h"
#include "jinete/jfont.h"
#include "jinete/jgrid.h"
#include "jinete/jhook.h"

View File

@ -68,7 +68,7 @@ int vaca_main()
status = app.run();
}
catch (jexception& e) {
catch (ase_exception& e) {
e.show();
}
catch (std::exception& e) {

View File

@ -26,6 +26,7 @@
#include "Vaca/Bind.h"
#include "jinete/jinete.h"
#include "ase_exception.h"
#include "modules/gui.h"
#include "tinyxml.h"
@ -53,7 +54,7 @@ Widget* load_widget_from_xmlfile(const char* xmlFilename, const char* widgetName
TiXmlDocument doc;
if (!doc.LoadFile(xmlFilename))
throw jexception(&doc);
throw ase_exception(&doc);
// search the requested widget
TiXmlHandle handle(&doc);