tryParse

Same as parse, but returning an error message instead of throwing. Useful for high-volume parsing.

tryParse
@trusted
()

Examples

Parse list of URLs and write any errors to stderr with column information.

1 import std.stdio : stderr;
2 
3 auto urls = ["irc://example.com", "ircs://example.org/foo?pass"];
4 
5 foreach(url; urls)
6 {
7 	ConnectionInfo info;
8 
9 	if(auto error = url.tryParse(info))
10 	{
11 		stderr.writefln("Error parsing URL:\n%s\n%*s\n%s", url, error.location + 1, "^", error.message);
12 		continue;
13 	}
14 
15 	// Use `info`
16 }

Meta