niks
niks

Reputation: 659

Possible exeptions when uploading/downloading files to Google Cloud Storage

I am using .NET Google.Cloud.Storage.V1 library to upload and download files to and from Google Cloud Storage. I am interested in Exception handling. I know it is a bad practice to catch general Exception therefore I am trying to sort out what types of exceptions could I encounter. So far I have found these three:

1) HttpRequestException when something is wrong with connection

2) OperationCanceledException this might be thrown when connection is lost during started upload/download

3) GoogleApiException when file does not exist in cloud, bucket is already existing, etc.

Is there anything else I should be aware of?

Upvotes: 0

Views: 232

Answers (1)

D Stanley
D Stanley

Reputation: 152634

Well, it's "bad practice" because you typically only want to catch exceptions when you can do something about them. If you don't know what types of exceptions are thrown, what can you do to handle them?

The typical practice is to catch uncaught exceptions as high up the call stack as possible where you can do something more graceful than shutting down the process. For web apps this may mean redirecting to an error page, for forms it may be showing a message box, etc.

So if you are only catching exceptions to do general logging or something basic, there's nothing wrong with catching Exception.

To answer the actual question, .NET doesn't have metadata to indicate what exceptions could be thrown like Java or other platforms do. You'd have to rely on the documentation, if any. Plus, it would be an implementation detail that would be subject to change without breaking compatibility.

Upvotes: 1

Related Questions