Silent exceptions in try/catch in debug mode (howto)

D-ratiseur ThisAdressDoesntExist at nowhere.fr
Thu Mar 7 18:27:22 PST 2013


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...


More information about the Digitalmars-d mailing list