C++

Topic: Exceptions

Explain about Designing With Exceptions with example ?

When implementing the packages which make up your application, such as your core graphics engine, it is very useful to define an exception hierarchy to utilize. This is useful for delineating kinds of exceptions as well as translating error codes into useful string messages. An example of this is the standard exceptions of the Standard C++ Library.A simple base class exception type can contain an error message string into which you can place your exception information. Specifying constructors which take parameters that specify the file and line number ( which typically can obtained from __FILE__ and __LINE__ ) and a string message allows for an easy way of storing the origin of the exception. You can also put a simple method for logging the exception which can be called in the constructor of a concrete exception class.I've also defined exception classes which translate DirectX error codes into a human readable message. If a component in the game engine package throws an exception it is always of a type derived from the base exception class of the package.In general, if you are going to throw an exception, you might as well gather up as much knowledge about the exception then because you are already paying a huge performance penalty for throwing the exception. Also, if the act of throwing your exception happens to cause memory exhaustion, there is guaranteed to be enough memory free to throw a bad_alloc exception. My experience has been that you'll likely get terminated by the operating system before bad_alloc is thrown, however in either case you're already in a world of hurt.I'll admit that I've opted-out of using exception specifications in my DirectX wrapper package in order to avoid adding superfluous try blocks.Also, since the exception classes themselves log the error message I can make my catch blocks either catch-all handlers or for my base exception class and still log exception information automatically. It is probably best to use the specific handler in places where only your own exception classes will be thrown and use the catch-all when making calls into APIs which may be throwing anything; this second case includes calling new() and its potential throw of bad_alloc. And I generally have one catch handler for the try block in order to simplify program flow control.

Browse random answers:

What is Exceptions in c++ ?
Can we generate a C++ source code from the binary file?
what is Un handled exception(KERNEL32.DLL):0xE06D7363 in the context of exception handling? pls answer to my mail id.in the flg code i got a problem.i want to know the entire steps followed in exception handling in this program.#include <iostream>using namespace std;int main(){ cout << "Start"; try  { // start a try block cout << "Inside try block"; cout << "Still inside try block"; throw 78; } catch (double i)  { // catch an error cout << "Caught an exception -- value is: "; cout << i << ""; } cout << "End"; return 0;}
How does throwing and catching exceptions differ from using setjmp and longjmp?
what is the difference betwen wait() and delay()?
How can I get around scope problems in a try/catch?
Explain exception specifications with example ?
Explain about standard exceptions with example ?
Explain about try, catch, and throw Statements (C++) ?
Exceptions are hard to ignore, unlike error codes. ?
What are C++ Exception  Examples ?
Explain about Unhandled C++ Exceptions ?
Explain about exception Handling Overhead ?
Explain about Mixing C (Structured) and C++ Exceptions ?
Explain about Overview of C++ Exception Handling with example ?
Explain about Implications of Using Exceptions with example ?
Explain about Designing With Exceptions with example ?
Explain about exceptions in Real-Time Systems ?
Explain about exception Handling Philosophies with example ?
Explain about exceptions in an Array-Based Stack ?
How many exceptions in a List-Based Stack ?
What are some ways try / catch / throw can improve software quality? 
How do exceptions simplify my function return type and parameter types? 
What does it mean that exceptions separate the "good path" (or "happy path") from the "bad path"? 
Exception handling seems to make my life more difficult; clearly I'm not the problem, am I?? 
How can I handle a destructor that fails? 
How can I handle a constructor that fails? 
How should I handle resources if my constructors may throw exceptions? 
What is exception-safe code? 
Explain about exception Neutrality ?
Explain how we implement exception handling in C++  
Explain terminate() and unexpected() function  ?
Exception handling concept  ?
Describe the way to handle run time error in C++.