Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 07, 2013 Silent exceptions in try/catch in debug mode (howto) | ||||
---|---|---|---|---|
| ||||
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 ? |
March 07, 2013 Re: Silent exceptions in try/catch in debug mode (howto) | ||||
---|---|---|---|---|
| ||||
Posted in reply to D-ratiseur | 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. :) |
March 08, 2013 Re: Silent exceptions in try/catch in debug mode (howto) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 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...
|
March 08, 2013 Re: Silent exceptions in try/catch in debug mode (howto) | ||||
---|---|---|---|---|
| ||||
Posted in reply to D-ratiseur | 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.
|
Copyright © 1999-2021 by the D Language Foundation