try_catch

try {

//statements
//no throw statement for bad_alloc

}
catch (type var){

//statements
//catch bad_alloc
}

VS

ptr_var=new (nothrow) [size]

whats the difference and why even if bad_alloc not defined in iostream catch can catch bad_alloc error?
nothrow version of new does not throw bad_alloc. Instead, it will return a NULL (nullptr?) pointer. This is useful for when you don't care to use exceptions at all.

As for the second portion of the question, you'll have to provide more context for the given problem.
ok then how come catch handles error even though throw is not used in try statement?
You will have to provide more context.
You mean that you (unsuccessfully) allocate memory with new or malloc and get try to be executed?
yee
What header you need for bad_alloc:

http://www.cplusplus.com/reference/new/bad_alloc/?kw=bad_alloc

catch handles something when it's thrown. Otherwise it does nothing
Topic archived. No new replies allowed.