aboutsummaryrefslogtreecommitdiff
path: root/Mammoth/Couscous/mammoth/internal/util/PassThroughException.cs
blob: 88597e31453ebf2074d92f058908acb089805a81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using Mammoth.Couscous.java.lang;
using Mammoth.Couscous.java.io;

namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.util {
	internal class PassThroughException : RuntimeException {
		internal static T wrap<T>(SupplierWithException<T, IOException> supplier) {
			try {
				return supplier.get();
			} catch (IOException exception) {
				throw new PassThroughException(exception);
			}
		}

		internal static T unwrap<T>(SupplierWithException<T, IOException> supplier) {
			try {
				return supplier.get();
			} catch (PassThroughException exception) {
				throw exception._exception;
			}
		}
    
		private readonly IOException _exception;
		
		internal PassThroughException(IOException exception) {
			_exception = exception;
		}
	}
}