digitalmars.D.learn - scope block do not handle failure, but try-catch does
- Suliman (7/7) Dec 11 2014 string dbname = config.getKey("dbname1");
- Michael (6/13) Dec 11 2014 I'm not 100% sure on this, but I suspect you have to declare the
- Suliman (12/12) Dec 13 2014 If I right understand scope is not good for checking if one of
- Suliman (13/13) Dec 13 2014 I reread docs and understood that scope not for such case.
- drug (13/26) Dec 14 2014 What you need probably is the following:
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (3/31) Dec 15 2014 Unfortunately you don't have access to the exception object
- drug (3/5) Dec 15 2014 Ah, yes, it has to be without msg.msg
string dbname = config.getKey("dbname1"); scope(failure) writeln("look like dbname is missing"); I am using dini and trying to throw exception if value can't be extract from config. If I am wrap it's in try-сефср block it's work or. But in this situation scope block do not execute and I see only stack tracing error on console. Why? What's wrong. By idea if block failure scope should execute
Dec 11 2014
On Thursday, 11 December 2014 at 20:40:40 UTC, Suliman wrote:string dbname = config.getKey("dbname1"); scope(failure) writeln("look like dbname is missing"); I am using dini and trying to throw exception if value can't be extract from config. If I am wrap it's in try-сефср block it's work or. But in this situation scope block do not execute and I see only stack tracing error on console. Why? What's wrong. By idea if block failure scope should executeI'm not 100% sure on this, but I suspect you have to declare the scope(failure) before you call the code that might execute it. e.g. scope(failure) writeln("Looks like the dbname is missing"); string dbname = config.getKey("dbname1");
Dec 11 2014
If I right understand scope is not good for checking if one of function is fail. For example: string dbpass = config.getKey("dbpass"); string dbpass = config.getKey("dbpass"); string dbhost = config.getKey("dbhost"); string dbport = config.getKey("dbport"); if I will try to add scope(failure) writeln("bla-bla-bla") after every function I will execute all writeln("bla-bla-bla") even if second function, for example, are failed. Is there any other way to do not wrap all function in try-catch block, but check if they was failed in short form?
Dec 13 2014
I reread docs and understood that scope not for such case. Next code is do what I need: try { string dbname = config.getKey("dbname"); string dbpass = config.getKey("dbpass"); string dbhost = config.getKey("dbhost"); string dbport = config.getKey("dbport"); } catch (Exception msg) { writeln("Can't parse config: %s", msg.msg); }
Dec 13 2014
On 13.12.2014 23:26, Suliman wrote:I reread docs and understood that scope not for such case. Next code is do what I need: try { string dbname = config.getKey("dbname"); string dbpass = config.getKey("dbpass"); string dbhost = config.getKey("dbhost"); string dbport = config.getKey("dbport"); } catch (Exception msg) { writeln("Can't parse config: %s", msg.msg); }What you need probably is the following: string dbpass, dbhost, dbport; { // This bracket is intended to define new scope // New if in the current scope from now any failure occurs // the compiler will call writeln with message scope(failure) writeln("Can't parse config: %s", msg.msg); dbname = config.getKey("dbname"); dbpass = config.getKey("dbpass"); dbhost = config.getKey("dbhost"); dbport = config.getKey("dbport"); } // the current scope ends, so if a failure happens later writeln won't be called
Dec 14 2014
On Monday, 15 December 2014 at 07:41:40 UTC, drug wrote:On 13.12.2014 23:26, Suliman wrote:Unfortunately you don't have access to the exception object inside the `scope(failure)` block.I reread docs and understood that scope not for such case. Next code is do what I need: try { string dbname = config.getKey("dbname"); string dbpass = config.getKey("dbpass"); string dbhost = config.getKey("dbhost"); string dbport = config.getKey("dbport"); } catch (Exception msg) { writeln("Can't parse config: %s", msg.msg); }What you need probably is the following: string dbpass, dbhost, dbport; { // This bracket is intended to define new scope // New if in the current scope from now any failure occurs // the compiler will call writeln with message scope(failure) writeln("Can't parse config: %s", msg.msg); dbname = config.getKey("dbname"); dbpass = config.getKey("dbpass"); dbhost = config.getKey("dbhost"); dbport = config.getKey("dbport"); } // the current scope ends, so if a failure happens later writeln won't be called
Dec 15 2014
On 15.12.2014 12:22, "Marc Schütz" <schuetzm gmx.net>" wrote:Unfortunately you don't have access to the exception object inside the `scope(failure)` block.Ah, yes, it has to be without msg.msg scope(failure) writeln("Something is wrong");
Dec 15 2014