The TryXXX Method Pattern - CSharp Custom Type

CSharp examples for Custom Type:Exception

Introduction

When writing a method you can choose to return some kind of failure code or throw an exception.

An example of this is the int type, which defines two versions of its Parse method:

public int Parse     (string input);
public bool TryParse (string input, out int returnValue);

If parsing fails, Parse throws an exception; TryParse returns false.


Related Tutorials