www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Silent exceptions in try/catch in debug mode (howto)

reply "D-ratiseur" <ThisAdressDoesntExist nowhere.fr> writes:
Hello, is it possible to hide an exception with an empty "catch"
block ?
---
try{
     //somestuff
}
catch{
    // an error ocurred but make someotherstuff and continue
}
---
I'm in a console program and running some unittests with the
-debug switch also set(but I don't debug I just run the appli.).
the console app does not continue while I would need the appli to
get on running. Actually I need to determinate if a segmentation
error is triggered in the try block or not and let the program
continue. But the program always stops...
Is it possible ? How could I shut down an exception in D ?
Mar 07 2013
next sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 03/07/2013 01:31 PM, D-ratiseur wrote:
 Hello, is it possible to hide an exception with an empty "catch"
 block ?
 ---
 try{
 //somestuff
 }
 catch{
 // an error ocurred but make someotherstuff and continue
 }
import std.stdio; unittest { try { writeln("throwing"); throw new Exception("unfortunate"); } catch (Exception exc) { } writeln("life goes on"); } void main() {} Note that some exceptions are not descendents of Exception: Throwable / \ Error Exception If you really have to, you can catch by Error or Throwable. However, catching by Error or Throwable is not advisable because you can't be sure of the state of the program when such an exception is thrown.
 ---
 I'm in a console program and running some unittests with the
 -debug switch also set(but I don't debug I just run the appli.).
 the console app does not continue while I would need the appli to
 get on running. Actually I need to determinate if a segmentation
 error is triggered in the try block or not and let the program
 continue. But the program always stops...
 Is it possible ? How could I shut down an exception in D ?
Unfortunately, segmentation faults are not translated to exceptions. Ali P.S. This thread would be interesting to people who follow the D.learn newsgroup. :)
Mar 07 2013
parent "D-ratiseur" <ThisAdressDoesntExist nowhere.fr> writes:
On Thursday, 7 March 2013 at 22:38:05 UTC, Ali Çehreli wrote:
 On 03/07/2013 01:31 PM, D-ratiseur wrote:
 Hello, is it possible to hide an exception with an empty
"catch"
 block ?
 ---
 try{
 //somestuff
 }
 catch{
 // an error ocurred but make someotherstuff and continue
 }
import std.stdio; unittest { try { writeln("throwing"); throw new Exception("unfortunate"); } catch (Exception exc) { } writeln("life goes on"); } void main() {} Note that some exceptions are not descendents of Exception: Throwable / \ Error Exception If you really have to, you can catch by Error or Throwable. However, catching by Error or Throwable is not advisable because you can't be sure of the state of the program when such an exception is thrown.
 ---
 I'm in a console program and running some unittests with the
 -debug switch also set(but I don't debug I just run the
appli.).
 the console app does not continue while I would need the
appli to
 get on running. Actually I need to determinate if a
segmentation
 error is triggered in the try block or not and let the program
 continue. But the program always stops...
 Is it possible ? How could I shut down an exception in D ?
Unfortunately, segmentation faults are not translated to exceptions. Ali P.S. This thread would be interesting to people who follow the D.learn newsgroup. :)
Yes probably...You seem to say that I've posted on the wrong section but actually I post directly from dlang.org, anonymously. I'll try to chose the right section next time because nowadays it's so rare to find some free-posting-boards...
Mar 07 2013
prev sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Thursday, 7 March 2013 at 21:31:48 UTC, D-ratiseur wrote:
 Hello, is it possible to hide an exception with an empty "catch"
 block ?
 ---
 try{
     //somestuff
 }
 catch{
    // an error ocurred but make someotherstuff and continue
 }
 ---
 I'm in a console program and running some unittests with the
 -debug switch also set(but I don't debug I just run the appli.).
 the console app does not continue while I would need the appli 
 to
 get on running. Actually I need to determinate if a segmentation
 error is triggered in the try block or not and let the program
 continue. But the program always stops...
 Is it possible ? How could I shut down an exception in D ?
According to the grammar, try { } catch(...) {} is supposed t work. I never tested it, so I can't really say more.
Mar 07 2013