www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to get rid of "nothrow" ?

reply Vinod K Chandran <kcvinu82 gmail.com> writes:
Hi all,
I am trying to create a win32 based gui in dlang. So far so good. 
I can create and display my window on screen. But for handling 
messages, i planned to write something like message crackers in 
c++. But since, my WndProc function is a "nothrow" function, i 
cannot use any function without "nothorw" in that WndProc. How to 
solve this problem ?
May 17 2020
parent reply Olivier Pisano <olivier.pisano laposte.net> writes:
On Sunday, 17 May 2020 at 09:27:40 UTC, Vinod K Chandran wrote:
 Hi all,
 I am trying to create a win32 based gui in dlang. So far so 
 good. I can create and display my window on screen. But for 
 handling messages, i planned to write something like message 
 crackers in c++. But since, my WndProc function is a "nothrow" 
 function, i cannot use any function without "nothorw" in that 
 WndProc. How to solve this problem ?
Hi, You need to catch any exceptions inside of your WndProc so they don't propagate: LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) nothrow { try { // your code logic here may call throwing functions } catch (Exception e) { // You should log exceptions here } }
May 17 2020
parent reply Vinod K Chandran <kcvinu82 gmail.com> writes:
On Sunday, 17 May 2020 at 09:50:00 UTC, Olivier Pisano wrote:
 On Sunday, 17 May 2020 at 09:27:40 UTC, Vinod K Chandran wrote:
 Hi all,
 I am trying to create a win32 based gui in dlang. So far so 
 good. I can create and display my window on screen. But for 
 handling messages, i planned to write something like message 
 crackers in c++. But since, my WndProc function is a "nothrow" 
 function, i cannot use any function without "nothorw" in that 
 WndProc. How to solve this problem ?
Hi, You need to catch any exceptions inside of your WndProc so they don't propagate: LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) nothrow { try { // your code logic here may call throwing functions } catch (Exception e) { // You should log exceptions here } }
Hi, Thanks a lot. Let me try.
May 17 2020
parent reply Vinod K Chandran <kcvinu82 gmail.com> writes:
On Sunday, 17 May 2020 at 14:21:41 UTC, Vinod K Chandran wrote:
 On Sunday, 17 May 2020 at 09:50:00 UTC, Olivier Pisano wrote:
 On Sunday, 17 May 2020 at 09:27:40 UTC, Vinod K Chandran wrote:
 Hi all,
 I am trying to create a win32 based gui in dlang. So far so 
 good. I can create and display my window on screen. But for 
 handling messages, i planned to write something like message 
 crackers in c++. But since, my WndProc function is a 
 "nothrow" function, i cannot use any function without 
 "nothorw" in that WndProc. How to solve this problem ?
Hi, You need to catch any exceptions inside of your WndProc so they don't propagate: LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) nothrow { try { // your code logic here may call throwing functions } catch (Exception e) { // You should log exceptions here } }
Hi, Thanks a lot. Let me try.
It worked. Thanks :) I have one more question. Which is better, to include all the switch cases inside a single try catch or write separate try catch for each switch cases ?
May 17 2020
parent reply drug <drug2004 bk.ru> writes:
17.05.2020 17:35, Vinod K Chandran пишет:
 
 It worked. Thanks :) I have one more question. Which is better, to 
 include all the switch cases inside a single try catch or write separate 
 try catch for each switch cases ?
all the switch cases inside a single try catch is better
May 17 2020
parent reply Vinod K Chandran <kcvinu82 gmail.com> writes:
On Sunday, 17 May 2020 at 19:37:05 UTC, drug wrote:
 17.05.2020 17:35, Vinod K Chandran пишет:
 
 It worked. Thanks :) I have one more question. Which is 
 better, to include all the switch cases inside a single try 
 catch or write separate try catch for each switch cases ?
all the switch cases inside a single try catch is better
Thanks a lot. :)
May 18 2020
parent drug <drug2004 bk.ru> writes:
On 5/18/20 11:47 PM, Vinod K Chandran wrote:
 On Sunday, 17 May 2020 at 19:37:05 UTC, drug wrote:
 17.05.2020 17:35, Vinod K Chandran пишет:
 It worked. Thanks :) I have one more question. Which is better, to 
 include all the switch cases inside a single try catch or write 
 separate try catch for each switch cases ?
all the switch cases inside a single try catch is better
Thanks a lot. :)
Frankly speaking in some cases separate try catch blocks will be more suitable but while you do not see the difference in your case then use the single block for everything
May 18 2020