Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

Several classes for exception handling

, 19 Jan 2002
C++ wrappers for stack trace, unhandled exception and win32 structured exceptions
exception_exe.zip
Exception.exe
Exception.pdb
exception_src.zip
Exception.dsp
Exception.dsw
Exception.plg
/*
 Copyright (c) 2002 
 Author: Konstantin Boukreev 
 E-mail: konstantin@mail.primorye.ru 
 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"

namespace
{
	// 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(); }
	 private:
		std::string m_s;
	};
}

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

/*
class bug_check : public exception2 
{
 public:
	  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.

License

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

Share

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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 20 Jan 2002
Article Copyright 2002 by Konstantin Boukreev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid