Terminate called without an active exception (throw in catch all expression)











up vote
0
down vote

favorite












I have a code block like this:



namespace bi = boost::intrusive;

struct Container {
struct Item {
bi::set_member_hook<> link;
int x;
};

struct Cmp {
bool opeartor()(Item const& it1, Item const &it2) const {
return it1.x < it2.x;
}
};
using Set = typename bi::set<Item,
bi::member_hook<Item, bi::set_member_hook<>, &Item::link>,
bi::compare<Cmp>,
bi::constant_time_size<false>
>;



Container(Container const& o) {
auto cloner = (const Item &x) {
return current_allocator().construct<Item>(x);
};

with_allocator(_alloctor, [&] {
new (&_data) Set;

_data.clone_from(o._data, cloner, current_deleter<Item>());
}
}


private:
Set _data;
};


The program sometime terminated with this message:




terminate called without an active exception




I found an answer from stackoverflow that because of throw was called without an active exception. But if without an active exception, then it can not reach the catch block.



I'm sorry for my bad English



EDIT: The code example was updated.



EDIT 2: Correct the code as @:RemyLebeau recommended, and the bug still happen.










share|improve this question




















  • 2




    Please provide a Minimal, Complete, and Verifiable example showing how you are throwing the initial exception. And FYI, this code won't compile since ptr is not in scope inside the catch block to pass to free_memory(). In this example, allocate_memory() should be above the try block, there is no point in calling free_memory() if allocate_memory() fails: complex_struct *ptr = allocate_memory(); try { clone(ptr, other); } catch(...) { free_memory(ptr); throw; }
    – Remy Lebeau
    Nov 20 at 3:14






  • 1




    Why are you declaring a non-pointer Set member and then calling placement-new on it for the same type? That is completely wrong, and totally unnecessary. Get rid of the new, as the _data member is already fully constructed by the compiler before your constructor's body is entered. And as such, you don't need to call the member'd destructor manually if your constructor throws, the compiler will handle that for you, so get rid of your try/catch, too. And remove your noexcept specifier, since your constructor can clearly throw an exception
    – Remy Lebeau
    Nov 20 at 4:14












  • @RemyLebeau I'm sorry, I used a custom allocator, and did not put the code here. I want items will be allocated using _allocator. The function with_allocator impl RAII idiom, then the function current_allocator() will return exactly _allocator.
    – Phạm Văn Thông
    Nov 20 at 4:25










  • Container(Container const& o) { auto cloner = ...; _data.clone_from(o._data, cloner, current_deleter<Item>()); } That is all your copy constructor needs. Assuming simply Container(Container const& o) : _data(o._data) {} or even just Container(Container const& o) = default; is not sufficient to copy a bi::set to another (I don't use boost)
    – Remy Lebeau
    Nov 20 at 4:26






  • 1




    Whether you use a custom allocator or not, calling placement-new on a previously constructed object is still wrong. Set _data; is a fully constructed object, so new (&_data) Set; risks leaking or even corrupting memory. If you want to use placement-new, you need to change _data to char _data[sizeof(Set)] or equivalent instead, and then save and use the Set* pointer that placement-new returns so you can access the Set object correctly.
    – Remy Lebeau
    Nov 20 at 4:30

















up vote
0
down vote

favorite












I have a code block like this:



namespace bi = boost::intrusive;

struct Container {
struct Item {
bi::set_member_hook<> link;
int x;
};

struct Cmp {
bool opeartor()(Item const& it1, Item const &it2) const {
return it1.x < it2.x;
}
};
using Set = typename bi::set<Item,
bi::member_hook<Item, bi::set_member_hook<>, &Item::link>,
bi::compare<Cmp>,
bi::constant_time_size<false>
>;



Container(Container const& o) {
auto cloner = (const Item &x) {
return current_allocator().construct<Item>(x);
};

with_allocator(_alloctor, [&] {
new (&_data) Set;

_data.clone_from(o._data, cloner, current_deleter<Item>());
}
}


private:
Set _data;
};


The program sometime terminated with this message:




terminate called without an active exception




I found an answer from stackoverflow that because of throw was called without an active exception. But if without an active exception, then it can not reach the catch block.



I'm sorry for my bad English



EDIT: The code example was updated.



EDIT 2: Correct the code as @:RemyLebeau recommended, and the bug still happen.










share|improve this question




















  • 2




    Please provide a Minimal, Complete, and Verifiable example showing how you are throwing the initial exception. And FYI, this code won't compile since ptr is not in scope inside the catch block to pass to free_memory(). In this example, allocate_memory() should be above the try block, there is no point in calling free_memory() if allocate_memory() fails: complex_struct *ptr = allocate_memory(); try { clone(ptr, other); } catch(...) { free_memory(ptr); throw; }
    – Remy Lebeau
    Nov 20 at 3:14






  • 1




    Why are you declaring a non-pointer Set member and then calling placement-new on it for the same type? That is completely wrong, and totally unnecessary. Get rid of the new, as the _data member is already fully constructed by the compiler before your constructor's body is entered. And as such, you don't need to call the member'd destructor manually if your constructor throws, the compiler will handle that for you, so get rid of your try/catch, too. And remove your noexcept specifier, since your constructor can clearly throw an exception
    – Remy Lebeau
    Nov 20 at 4:14












  • @RemyLebeau I'm sorry, I used a custom allocator, and did not put the code here. I want items will be allocated using _allocator. The function with_allocator impl RAII idiom, then the function current_allocator() will return exactly _allocator.
    – Phạm Văn Thông
    Nov 20 at 4:25










  • Container(Container const& o) { auto cloner = ...; _data.clone_from(o._data, cloner, current_deleter<Item>()); } That is all your copy constructor needs. Assuming simply Container(Container const& o) : _data(o._data) {} or even just Container(Container const& o) = default; is not sufficient to copy a bi::set to another (I don't use boost)
    – Remy Lebeau
    Nov 20 at 4:26






  • 1




    Whether you use a custom allocator or not, calling placement-new on a previously constructed object is still wrong. Set _data; is a fully constructed object, so new (&_data) Set; risks leaking or even corrupting memory. If you want to use placement-new, you need to change _data to char _data[sizeof(Set)] or equivalent instead, and then save and use the Set* pointer that placement-new returns so you can access the Set object correctly.
    – Remy Lebeau
    Nov 20 at 4:30















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a code block like this:



namespace bi = boost::intrusive;

struct Container {
struct Item {
bi::set_member_hook<> link;
int x;
};

struct Cmp {
bool opeartor()(Item const& it1, Item const &it2) const {
return it1.x < it2.x;
}
};
using Set = typename bi::set<Item,
bi::member_hook<Item, bi::set_member_hook<>, &Item::link>,
bi::compare<Cmp>,
bi::constant_time_size<false>
>;



Container(Container const& o) {
auto cloner = (const Item &x) {
return current_allocator().construct<Item>(x);
};

with_allocator(_alloctor, [&] {
new (&_data) Set;

_data.clone_from(o._data, cloner, current_deleter<Item>());
}
}


private:
Set _data;
};


The program sometime terminated with this message:




terminate called without an active exception




I found an answer from stackoverflow that because of throw was called without an active exception. But if without an active exception, then it can not reach the catch block.



I'm sorry for my bad English



EDIT: The code example was updated.



EDIT 2: Correct the code as @:RemyLebeau recommended, and the bug still happen.










share|improve this question















I have a code block like this:



namespace bi = boost::intrusive;

struct Container {
struct Item {
bi::set_member_hook<> link;
int x;
};

struct Cmp {
bool opeartor()(Item const& it1, Item const &it2) const {
return it1.x < it2.x;
}
};
using Set = typename bi::set<Item,
bi::member_hook<Item, bi::set_member_hook<>, &Item::link>,
bi::compare<Cmp>,
bi::constant_time_size<false>
>;



Container(Container const& o) {
auto cloner = (const Item &x) {
return current_allocator().construct<Item>(x);
};

with_allocator(_alloctor, [&] {
new (&_data) Set;

_data.clone_from(o._data, cloner, current_deleter<Item>());
}
}


private:
Set _data;
};


The program sometime terminated with this message:




terminate called without an active exception




I found an answer from stackoverflow that because of throw was called without an active exception. But if without an active exception, then it can not reach the catch block.



I'm sorry for my bad English



EDIT: The code example was updated.



EDIT 2: Correct the code as @:RemyLebeau recommended, and the bug still happen.







c++ exception-handling






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 1:14

























asked Nov 20 at 2:48









Phạm Văn Thông

14710




14710








  • 2




    Please provide a Minimal, Complete, and Verifiable example showing how you are throwing the initial exception. And FYI, this code won't compile since ptr is not in scope inside the catch block to pass to free_memory(). In this example, allocate_memory() should be above the try block, there is no point in calling free_memory() if allocate_memory() fails: complex_struct *ptr = allocate_memory(); try { clone(ptr, other); } catch(...) { free_memory(ptr); throw; }
    – Remy Lebeau
    Nov 20 at 3:14






  • 1




    Why are you declaring a non-pointer Set member and then calling placement-new on it for the same type? That is completely wrong, and totally unnecessary. Get rid of the new, as the _data member is already fully constructed by the compiler before your constructor's body is entered. And as such, you don't need to call the member'd destructor manually if your constructor throws, the compiler will handle that for you, so get rid of your try/catch, too. And remove your noexcept specifier, since your constructor can clearly throw an exception
    – Remy Lebeau
    Nov 20 at 4:14












  • @RemyLebeau I'm sorry, I used a custom allocator, and did not put the code here. I want items will be allocated using _allocator. The function with_allocator impl RAII idiom, then the function current_allocator() will return exactly _allocator.
    – Phạm Văn Thông
    Nov 20 at 4:25










  • Container(Container const& o) { auto cloner = ...; _data.clone_from(o._data, cloner, current_deleter<Item>()); } That is all your copy constructor needs. Assuming simply Container(Container const& o) : _data(o._data) {} or even just Container(Container const& o) = default; is not sufficient to copy a bi::set to another (I don't use boost)
    – Remy Lebeau
    Nov 20 at 4:26






  • 1




    Whether you use a custom allocator or not, calling placement-new on a previously constructed object is still wrong. Set _data; is a fully constructed object, so new (&_data) Set; risks leaking or even corrupting memory. If you want to use placement-new, you need to change _data to char _data[sizeof(Set)] or equivalent instead, and then save and use the Set* pointer that placement-new returns so you can access the Set object correctly.
    – Remy Lebeau
    Nov 20 at 4:30
















  • 2




    Please provide a Minimal, Complete, and Verifiable example showing how you are throwing the initial exception. And FYI, this code won't compile since ptr is not in scope inside the catch block to pass to free_memory(). In this example, allocate_memory() should be above the try block, there is no point in calling free_memory() if allocate_memory() fails: complex_struct *ptr = allocate_memory(); try { clone(ptr, other); } catch(...) { free_memory(ptr); throw; }
    – Remy Lebeau
    Nov 20 at 3:14






  • 1




    Why are you declaring a non-pointer Set member and then calling placement-new on it for the same type? That is completely wrong, and totally unnecessary. Get rid of the new, as the _data member is already fully constructed by the compiler before your constructor's body is entered. And as such, you don't need to call the member'd destructor manually if your constructor throws, the compiler will handle that for you, so get rid of your try/catch, too. And remove your noexcept specifier, since your constructor can clearly throw an exception
    – Remy Lebeau
    Nov 20 at 4:14












  • @RemyLebeau I'm sorry, I used a custom allocator, and did not put the code here. I want items will be allocated using _allocator. The function with_allocator impl RAII idiom, then the function current_allocator() will return exactly _allocator.
    – Phạm Văn Thông
    Nov 20 at 4:25










  • Container(Container const& o) { auto cloner = ...; _data.clone_from(o._data, cloner, current_deleter<Item>()); } That is all your copy constructor needs. Assuming simply Container(Container const& o) : _data(o._data) {} or even just Container(Container const& o) = default; is not sufficient to copy a bi::set to another (I don't use boost)
    – Remy Lebeau
    Nov 20 at 4:26






  • 1




    Whether you use a custom allocator or not, calling placement-new on a previously constructed object is still wrong. Set _data; is a fully constructed object, so new (&_data) Set; risks leaking or even corrupting memory. If you want to use placement-new, you need to change _data to char _data[sizeof(Set)] or equivalent instead, and then save and use the Set* pointer that placement-new returns so you can access the Set object correctly.
    – Remy Lebeau
    Nov 20 at 4:30










2




2




Please provide a Minimal, Complete, and Verifiable example showing how you are throwing the initial exception. And FYI, this code won't compile since ptr is not in scope inside the catch block to pass to free_memory(). In this example, allocate_memory() should be above the try block, there is no point in calling free_memory() if allocate_memory() fails: complex_struct *ptr = allocate_memory(); try { clone(ptr, other); } catch(...) { free_memory(ptr); throw; }
– Remy Lebeau
Nov 20 at 3:14




Please provide a Minimal, Complete, and Verifiable example showing how you are throwing the initial exception. And FYI, this code won't compile since ptr is not in scope inside the catch block to pass to free_memory(). In this example, allocate_memory() should be above the try block, there is no point in calling free_memory() if allocate_memory() fails: complex_struct *ptr = allocate_memory(); try { clone(ptr, other); } catch(...) { free_memory(ptr); throw; }
– Remy Lebeau
Nov 20 at 3:14




1




1




Why are you declaring a non-pointer Set member and then calling placement-new on it for the same type? That is completely wrong, and totally unnecessary. Get rid of the new, as the _data member is already fully constructed by the compiler before your constructor's body is entered. And as such, you don't need to call the member'd destructor manually if your constructor throws, the compiler will handle that for you, so get rid of your try/catch, too. And remove your noexcept specifier, since your constructor can clearly throw an exception
– Remy Lebeau
Nov 20 at 4:14






Why are you declaring a non-pointer Set member and then calling placement-new on it for the same type? That is completely wrong, and totally unnecessary. Get rid of the new, as the _data member is already fully constructed by the compiler before your constructor's body is entered. And as such, you don't need to call the member'd destructor manually if your constructor throws, the compiler will handle that for you, so get rid of your try/catch, too. And remove your noexcept specifier, since your constructor can clearly throw an exception
– Remy Lebeau
Nov 20 at 4:14














@RemyLebeau I'm sorry, I used a custom allocator, and did not put the code here. I want items will be allocated using _allocator. The function with_allocator impl RAII idiom, then the function current_allocator() will return exactly _allocator.
– Phạm Văn Thông
Nov 20 at 4:25




@RemyLebeau I'm sorry, I used a custom allocator, and did not put the code here. I want items will be allocated using _allocator. The function with_allocator impl RAII idiom, then the function current_allocator() will return exactly _allocator.
– Phạm Văn Thông
Nov 20 at 4:25












Container(Container const& o) { auto cloner = ...; _data.clone_from(o._data, cloner, current_deleter<Item>()); } That is all your copy constructor needs. Assuming simply Container(Container const& o) : _data(o._data) {} or even just Container(Container const& o) = default; is not sufficient to copy a bi::set to another (I don't use boost)
– Remy Lebeau
Nov 20 at 4:26




Container(Container const& o) { auto cloner = ...; _data.clone_from(o._data, cloner, current_deleter<Item>()); } That is all your copy constructor needs. Assuming simply Container(Container const& o) : _data(o._data) {} or even just Container(Container const& o) = default; is not sufficient to copy a bi::set to another (I don't use boost)
– Remy Lebeau
Nov 20 at 4:26




1




1




Whether you use a custom allocator or not, calling placement-new on a previously constructed object is still wrong. Set _data; is a fully constructed object, so new (&_data) Set; risks leaking or even corrupting memory. If you want to use placement-new, you need to change _data to char _data[sizeof(Set)] or equivalent instead, and then save and use the Set* pointer that placement-new returns so you can access the Set object correctly.
– Remy Lebeau
Nov 20 at 4:30






Whether you use a custom allocator or not, calling placement-new on a previously constructed object is still wrong. Set _data; is a fully constructed object, so new (&_data) Set; risks leaking or even corrupting memory. If you want to use placement-new, you need to change _data to char _data[sizeof(Set)] or equivalent instead, and then save and use the Set* pointer that placement-new returns so you can access the Set object correctly.
– Remy Lebeau
Nov 20 at 4:30














2 Answers
2






active

oldest

votes

















up vote
0
down vote













I think the message




terminate called without an active exception




actually takes to mean




terminate called without an active C++ exception




terminate() may be called for many different reasons, not limited to unhandled C++ exceptions. The catch (...) clause only catches C++ exceptions. In your particular case, terminate() may be called within allocate_memory() or clone() directly, or by runtime due to unhandled non-C++ exceptions (like some low-level Windows exceptions that should be captured with SEH). In either case, the catch block is never entered.






share|improve this answer





















  • I used a framework which print backtrace when program was terminated. The last function in the reported call stack is this function. the clone() function used in my function is boost::intrusive::set::clone_from (I can not copy and pasted the code here because of security reason). I don't think that the compiler inline this function, then it should show up in the call stack if there is an exception.
    – Phạm Văn Thông
    Nov 20 at 3:30


















up vote
-1
down vote













You have called throw from catch but the catch was supposed to catch it. The throw should have been in try instead if I understood it correctly.






share|improve this answer

















  • 2




    A catch block can re-throw the exception it caught.
    – Remy Lebeau
    Nov 20 at 3:08












  • @RemyLebeau Yes, it surely can but in this case, it may cause the crash the application if it is not caught further. And that is my point. So how my statement is wrong?
    – Harsh
    Nov 20 at 4:02












  • your statement implies that throw cannot be called inside of catch, which is wrong. Regardless of whether the exception is caught higher up the call stack or not.
    – Remy Lebeau
    Nov 20 at 4:27










  • I said "The throw should have been in try instead if I understood it correctly.". Now how it implies that throw can't be in catch?
    – Harsh
    Nov 20 at 4:33











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385499%2fterminate-called-without-an-active-exception-throw-in-catch-all-expression%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













I think the message




terminate called without an active exception




actually takes to mean




terminate called without an active C++ exception




terminate() may be called for many different reasons, not limited to unhandled C++ exceptions. The catch (...) clause only catches C++ exceptions. In your particular case, terminate() may be called within allocate_memory() or clone() directly, or by runtime due to unhandled non-C++ exceptions (like some low-level Windows exceptions that should be captured with SEH). In either case, the catch block is never entered.






share|improve this answer





















  • I used a framework which print backtrace when program was terminated. The last function in the reported call stack is this function. the clone() function used in my function is boost::intrusive::set::clone_from (I can not copy and pasted the code here because of security reason). I don't think that the compiler inline this function, then it should show up in the call stack if there is an exception.
    – Phạm Văn Thông
    Nov 20 at 3:30















up vote
0
down vote













I think the message




terminate called without an active exception




actually takes to mean




terminate called without an active C++ exception




terminate() may be called for many different reasons, not limited to unhandled C++ exceptions. The catch (...) clause only catches C++ exceptions. In your particular case, terminate() may be called within allocate_memory() or clone() directly, or by runtime due to unhandled non-C++ exceptions (like some low-level Windows exceptions that should be captured with SEH). In either case, the catch block is never entered.






share|improve this answer





















  • I used a framework which print backtrace when program was terminated. The last function in the reported call stack is this function. the clone() function used in my function is boost::intrusive::set::clone_from (I can not copy and pasted the code here because of security reason). I don't think that the compiler inline this function, then it should show up in the call stack if there is an exception.
    – Phạm Văn Thông
    Nov 20 at 3:30













up vote
0
down vote










up vote
0
down vote









I think the message




terminate called without an active exception




actually takes to mean




terminate called without an active C++ exception




terminate() may be called for many different reasons, not limited to unhandled C++ exceptions. The catch (...) clause only catches C++ exceptions. In your particular case, terminate() may be called within allocate_memory() or clone() directly, or by runtime due to unhandled non-C++ exceptions (like some low-level Windows exceptions that should be captured with SEH). In either case, the catch block is never entered.






share|improve this answer












I think the message




terminate called without an active exception




actually takes to mean




terminate called without an active C++ exception




terminate() may be called for many different reasons, not limited to unhandled C++ exceptions. The catch (...) clause only catches C++ exceptions. In your particular case, terminate() may be called within allocate_memory() or clone() directly, or by runtime due to unhandled non-C++ exceptions (like some low-level Windows exceptions that should be captured with SEH). In either case, the catch block is never entered.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 3:15









Lingxi

8,2691953




8,2691953












  • I used a framework which print backtrace when program was terminated. The last function in the reported call stack is this function. the clone() function used in my function is boost::intrusive::set::clone_from (I can not copy and pasted the code here because of security reason). I don't think that the compiler inline this function, then it should show up in the call stack if there is an exception.
    – Phạm Văn Thông
    Nov 20 at 3:30


















  • I used a framework which print backtrace when program was terminated. The last function in the reported call stack is this function. the clone() function used in my function is boost::intrusive::set::clone_from (I can not copy and pasted the code here because of security reason). I don't think that the compiler inline this function, then it should show up in the call stack if there is an exception.
    – Phạm Văn Thông
    Nov 20 at 3:30
















I used a framework which print backtrace when program was terminated. The last function in the reported call stack is this function. the clone() function used in my function is boost::intrusive::set::clone_from (I can not copy and pasted the code here because of security reason). I don't think that the compiler inline this function, then it should show up in the call stack if there is an exception.
– Phạm Văn Thông
Nov 20 at 3:30




I used a framework which print backtrace when program was terminated. The last function in the reported call stack is this function. the clone() function used in my function is boost::intrusive::set::clone_from (I can not copy and pasted the code here because of security reason). I don't think that the compiler inline this function, then it should show up in the call stack if there is an exception.
– Phạm Văn Thông
Nov 20 at 3:30












up vote
-1
down vote













You have called throw from catch but the catch was supposed to catch it. The throw should have been in try instead if I understood it correctly.






share|improve this answer

















  • 2




    A catch block can re-throw the exception it caught.
    – Remy Lebeau
    Nov 20 at 3:08












  • @RemyLebeau Yes, it surely can but in this case, it may cause the crash the application if it is not caught further. And that is my point. So how my statement is wrong?
    – Harsh
    Nov 20 at 4:02












  • your statement implies that throw cannot be called inside of catch, which is wrong. Regardless of whether the exception is caught higher up the call stack or not.
    – Remy Lebeau
    Nov 20 at 4:27










  • I said "The throw should have been in try instead if I understood it correctly.". Now how it implies that throw can't be in catch?
    – Harsh
    Nov 20 at 4:33















up vote
-1
down vote













You have called throw from catch but the catch was supposed to catch it. The throw should have been in try instead if I understood it correctly.






share|improve this answer

















  • 2




    A catch block can re-throw the exception it caught.
    – Remy Lebeau
    Nov 20 at 3:08












  • @RemyLebeau Yes, it surely can but in this case, it may cause the crash the application if it is not caught further. And that is my point. So how my statement is wrong?
    – Harsh
    Nov 20 at 4:02












  • your statement implies that throw cannot be called inside of catch, which is wrong. Regardless of whether the exception is caught higher up the call stack or not.
    – Remy Lebeau
    Nov 20 at 4:27










  • I said "The throw should have been in try instead if I understood it correctly.". Now how it implies that throw can't be in catch?
    – Harsh
    Nov 20 at 4:33













up vote
-1
down vote










up vote
-1
down vote









You have called throw from catch but the catch was supposed to catch it. The throw should have been in try instead if I understood it correctly.






share|improve this answer












You have called throw from catch but the catch was supposed to catch it. The throw should have been in try instead if I understood it correctly.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 3:02









Harsh

1438




1438








  • 2




    A catch block can re-throw the exception it caught.
    – Remy Lebeau
    Nov 20 at 3:08












  • @RemyLebeau Yes, it surely can but in this case, it may cause the crash the application if it is not caught further. And that is my point. So how my statement is wrong?
    – Harsh
    Nov 20 at 4:02












  • your statement implies that throw cannot be called inside of catch, which is wrong. Regardless of whether the exception is caught higher up the call stack or not.
    – Remy Lebeau
    Nov 20 at 4:27










  • I said "The throw should have been in try instead if I understood it correctly.". Now how it implies that throw can't be in catch?
    – Harsh
    Nov 20 at 4:33














  • 2




    A catch block can re-throw the exception it caught.
    – Remy Lebeau
    Nov 20 at 3:08












  • @RemyLebeau Yes, it surely can but in this case, it may cause the crash the application if it is not caught further. And that is my point. So how my statement is wrong?
    – Harsh
    Nov 20 at 4:02












  • your statement implies that throw cannot be called inside of catch, which is wrong. Regardless of whether the exception is caught higher up the call stack or not.
    – Remy Lebeau
    Nov 20 at 4:27










  • I said "The throw should have been in try instead if I understood it correctly.". Now how it implies that throw can't be in catch?
    – Harsh
    Nov 20 at 4:33








2




2




A catch block can re-throw the exception it caught.
– Remy Lebeau
Nov 20 at 3:08






A catch block can re-throw the exception it caught.
– Remy Lebeau
Nov 20 at 3:08














@RemyLebeau Yes, it surely can but in this case, it may cause the crash the application if it is not caught further. And that is my point. So how my statement is wrong?
– Harsh
Nov 20 at 4:02






@RemyLebeau Yes, it surely can but in this case, it may cause the crash the application if it is not caught further. And that is my point. So how my statement is wrong?
– Harsh
Nov 20 at 4:02














your statement implies that throw cannot be called inside of catch, which is wrong. Regardless of whether the exception is caught higher up the call stack or not.
– Remy Lebeau
Nov 20 at 4:27




your statement implies that throw cannot be called inside of catch, which is wrong. Regardless of whether the exception is caught higher up the call stack or not.
– Remy Lebeau
Nov 20 at 4:27












I said "The throw should have been in try instead if I understood it correctly.". Now how it implies that throw can't be in catch?
– Harsh
Nov 20 at 4:33




I said "The throw should have been in try instead if I understood it correctly.". Now how it implies that throw can't be in catch?
– Harsh
Nov 20 at 4:33


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385499%2fterminate-called-without-an-active-exception-throw-in-catch-all-expression%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft