Click here to Skip to main content
12,953,230 members (81,023 online)
Click here to Skip to main content


121 bookmarked
Posted 19 Jan 2002

Several classes for exception handling

, 19 Jan 2002
C++ wrappers for stack trace, unhandled exception and win32 structured exceptions
 Copyright (c) 2002 
 Author: Konstantin Boukreev 
 Created: 16.01.2002 12:36:26
 Version: 1.0.0

 Permission to use, copy, modify, distribute and sell this software
 and its documentation for any purpose is hereby granted without fee,
 provided that the above copyright notice appear in all copies and
 that both that copyright notice and this permission notice appear
 in supporting documentation.  Konstantin Boukreev makes no representations
 about the suitability of this software for any purpose.
 It is provided "as is" without express or implied warranty.

 the exception class holding the call stack's information

 exception2 : std::exception
 try {
 catch(exception2& ex) {
	std::cout << ex.trace_call();


#ifndef _stdexcept2_b20f8ff9_4d70_4262_a60a_a615f3fbc8b3
#define _stdexcept2_b20f8ff9_4d70_4262_a60a_a615f3fbc8b3

#if _MSC_VER > 1000 
#pragma once
#endif // _MSC_VER > 1000

#include <sstream>
#include <string>
#include <exception>
#include "sym_engine.h"

	// the mixin class for exception
	struct call_stack
		call_stack (unsigned skip = 3)
			: m_s((skip == unsigned(-1)) ? "" : call_stack::get(skip))		
		static std::string get(unsigned skip = 2)
			std::stringstream ss(std::ios::out);		
			sym_engine::stack_trace(ss, skip);			
			return ss.str();		
		const char * stack_trace() const { return m_s.c_str(); }
		std::string m_s;

#pragma inline_depth(0) // must disable inlining due to using skip value
class exception2 : public std::exception, public call_stack 
	  exception2(const __exString& s, unsigned skip = 4 /* -1 for disable call stack*/)
		  : std::exception(s), call_stack(skip)		

class bug_check : public exception2 
	  bug_check() : exception2("bug check", 5) {}

#pragma inline_depth() // restore back the default value

#endif //_stdexcept2_b20f8ff9_4d70_4262_a60a_a615f3fbc8b3

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Konstantin Boukreev
Web Developer
Russian Federation Russian Federation
I am freelance programmer. About 3 years of experience in C++ and I would rather use ATL, STL, WTL but not MFC Smile | :) . Main backgrounds are Win32 API, COM and Networking. Now I am interested about AI (Neural Network, Fuzzy Logic and GA). Currently based in Vladivostok, Russia.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170525.1 | Last Updated 20 Jan 2002
Article Copyright 2002 by Konstantin Boukreev
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid