digitalmars.D - Silent exceptions in try/catch in debug mode (howto)
- D-ratiseur (17/17) Mar 07 2013 Hello, is it possible to hide an exception with an empty "catch"
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (24/41) Mar 07 2013 import std.stdio;
- D-ratiseur (5/52) Mar 07 2013 Yes probably...You seem to say that I've posted on the wrong
- deadalnix (3/21) Mar 07 2013 According to the grammar, try { } catch(...) {} is supposed t
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
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
On Thursday, 7 March 2013 at 22:38:05 UTC, Ali Çehreli wrote:On 03/07/2013 01:31 PM, D-ratiseur wrote: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...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 theappli.).the console app does not continue while I would need theappli toget on running. Actually I need to determinate if asegmentationerror 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
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