digitalmars.D.learn - Exception style
- Sean Campbell (11/11) Jun 25 2014 i know you can use both
 - bearophile (8/9) Jun 25 2014 Both are valid. Use the second when you want a more precise
 - Sean Campbell (3/12) Jun 25 2014 Thank you very much for the quick reply, and a method to save
 
i know you can use both
throw new Exception(msg);
and
module test;
class testException {
      this (string msg) {
           super("some error info : "~msg);
      }
}
throw new testException(msg);
but which one is better conforms to the d style?
 Jun 25 2014
Sean Campbell:but which one is better conforms to the d style?Both are valid. Use the second when you want a more precise exception in your code, this is common in larger programs. Keep in mind that you can allocate an exception in a point and throw it in another. This reduces the runtime allocations and should allow more nogc code. Bye, bearophile
 Jun 25 2014
On Wednesday, 25 June 2014 at 09:54:16 UTC, bearophile wrote:Sean Campbell:Thank you very much for the quick reply, and a method to save memory.but which one is better conforms to the d style?Both are valid. Use the second when you want a more precise exception in your code, this is common in larger programs. Keep in mind that you can allocate an exception in a point and throw it in another. This reduces the runtime allocations and should allow more nogc code. Bye, bearophile
 Jun 25 2014








 
 
 
 "Sean Campbell" <sycam.inc gmail.com>