Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOExceptions #97

Open
Aidan63 opened this issue Aug 28, 2024 · 0 comments
Open

IOExceptions #97

Aidan63 opened this issue Aug 28, 2024 · 0 comments
Labels

Comments

@Aidan63
Copy link
Owner

Aidan63 commented Aug 28, 2024

The IOException type is rather awkward to use, especially if you look at it from a coroutine point of view. If, for example, I'm only interested in the file not being found and I'm fine with other exceptions being bubbled up I'd have to write something like this.

try {
	FileSystem.info(path).modificationTime;

	// do other stuff
} catch (exn:IOException) {
	if (exn.type.match(FileNotFound)) {
		return false;
	}

	// rethrow exceptions we're not handling...
	throw exn;
}

Usually I'm all for reducing inheritance but with the built in type checking of catches, having exception sub classes for each exception type makes for nicer code and less likely to accidentally swallow errors.

try {
	FileSystem.info(path).modificationTime;

	// do other stuff
} catch (_:FileNotFoundException) {
	return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant