/* * Copyright (C) 2007 Tildeslash Ltd. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation. * * There are special exceptions to the terms and conditions of the GPL * as it is applied to this software. View the full text of the exception * in the file EXCEPTIONS accompanying this software distribution. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Copyright (c) 1994,1995,1996,1997 by David R. Hanson. * * 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, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * */ #include "Config.h" #include #include #include "Util.h" #include "Thread.h" #include "Exception.h" /** * Implementation of the Exception interface. Defines the Thread local * Exception stack and Exceptions used in the library. * * LEGAL NOTICE, the part that differs from the original code is Copyright * (C) Tildeslash Ltd. This implementation is licensed under the GPL * with Exceptions in the file EXCEPTIONS. The MIT license above applies * to the original and exceptional clever CII code which can be found at * this URL http://www.cs.princeton.edu/software/cii/ * * @version \$Id: Exception.c,v 1.14 2007/02/15 20:47:54 hauk Exp $ * @file */ /* ----------------------------------------------------------- Definitions */ #define T Exception_T /* Placeholder for system exceptions. */ Exception_T SQLException = {"SQLException"}; #ifdef ZILD_PACKAGE_PROTECTED #pragma GCC visibility push(hidden) #endif Exception_T AssertException = {"AssertException"}; /* Thread specific Exception stack */ ThreadData_T Exception_stack; /* ------------------------------------------------------------ Prototypes */ static void init_once(void); /* ----------------------------------------------------- Protected methods */ #ifdef PACKAGE_PROTECTED #pragma GCC visibility push(hidden) #endif void Exception_init() { #ifndef WIN32 pthread_once_t once_control = PTHREAD_ONCE_INIT; pthread_once(&once_control, init_once); #endif } #ifdef PACKAGE_PROTECTED #pragma GCC visibility pop #endif /* -------------------------------------------------------- Public methods */ void Exception_throw(const T *e, const char *func, const char *file, int line) { Exception_Frame *p= ThreadData_get(Exception_stack); assert(e); assert(e->name); if(p == NULL) { ABORT("Uncaught exception %s raised in %s at %s:%d\n", e->name, func?func:"?", file?file:"?", line); } else { p->exception= e; p->func= func; p->file= file; p->line= line; pop_exception_stack; longjmp(p->env, Exception_throwd); } } #ifdef ZILD_PACKAGE_PROTECTED #pragma GCC visibility push(hidden) #endif /* --------------------------------------------------------------- Private */ static void init_once(void) { ThreadData_create(Exception_stack); }