www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How catch any error in Dlang like Python try-except?

reply Marcone <marcone email.com> writes:
How catch any error in Dlang like Python tray-except?

It is very useful when making tests. But only who came from 
interpreted languages can understand.

Exemple:

import std;

void main()
{	
	try {
		writelnX("try function that not exist");
	} catch (Throwable e)
	{
		writeln("Error: %s".format(e.msg));
	}
}
Mar 14 2020
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 15 March 2020 at 02:11:21 UTC, Marcone wrote:
 It is very useful when making tests. But only who came from 
 interpreted languages can understand.
The compiler catches all compile errors. It is impossible to even run a program if there is even a single compile error. Thus they cannot be caught.
Mar 14 2020