Before I use Nito.MVVM, I used plain async/await and it was throwing me an aggregate exception and I could read into it and know what I have. But since Nito, my exceptions are ignored and the program jumps from async code block and continue executes. I know that it catch exceptions because when I put a breakpoint on catch(Exception ex)
line it breaks here but with ex = null
. I know that NotifyTask has properties to check if an exception was thrown but where I put it, it checks when Task is uncompleted, not when I need it.
View model:
public FileExplorerPageViewModel(INavigationService navigationService) { _navigationService = navigationService; _manager = new FileExplorerManager(); Files = NotifyTask.Create(GetFilesAsync("UniorDev", "GitRemote/GitRemote")); }
Private method:
private async Task<ObservableCollection<FileExplorerModel>> GetFilesAsync(string login, string reposName) { return new ObservableCollection<FileExplorerModel>(await _manager.GetFilesAsync(login, reposName)); }
Manager method(where exception throws):
public async Task<List<FileExplorerModel>> GetFilesAsync(string login, string reposName) { //try //{ var gitHubFiles = await GetGitHubFilesAsync(login, reposName); var gitRemoteFiles = new List<FileExplorerModel>(); foreach ( var file in gitHubFiles ) { if ( file.Type == ContentType.Symlink || file.Type == ContentType.Submodule ) continue; var model = new FileExplorerModel { Name = file.Name, FileType = file.Type.ToString() }; if ( model.IsFolder ) { var nextFiles = await GetGitHubFilesAsync(login, reposName); var count = nextFiles.Count; } model.FileSize = file.Size.ToString(); gitRemoteFiles.Add(model); } return gitRemoteFiles; //} //catch ( WebException ex ) //{ // throw new Exception("Something wrong with internet connection, try to On Internet "+ ex.Message); //} //catch ( Exception ex ) //{ // throw new Exception("Getting ExplorerFiles from github failed! "+ ex.Message); //} }
With try/catch or without it has the same effect. This behavior is anywhere where I have NotifyTask.
UpdateThere is no event, that fires when exception occurred, but there is Property Changed event, so I used it and added this code:
private void FilesOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) { throw new Exception("EXCEPTION"); bool failed; if ( Files.IsFaulted ) failed = true; }
And exception not fires. I added throw exception in App class (main class) and it fired. And when I have exceptions that come from XAML, it also fires. So maybe it not fires when it comes from a view model, or something else. I have no idea. Will be very happy for some help with it.Update
We deal with exception = null, but the question is still alive. What I wanna add, that I rarely this issue, when the app is starting to launch on the physic device. I read some info about it, and it doesn't seem to be related, but maybe it is: