Я получил эту функцию:
public async Task<bool> TryPlayElseStop(int reciterId, int chapterId) {
this.chapterId = chapterId;
var file = await RecitationUtils.TryGetAudioFile(reciterId, chapterId);
if (file != null) {
Play(file); // there should be an exception thrown here
return true;
} else {
Utils.Toast("Download the file first in the Recitation menu");
Stop();
return false;
}
}
private void Play(Tuple<MyFile, RealmRecitationFile> file) {
if (mediaPlayer == null)
InitMediaPlayer();
ResetCallbacks();
mediaPlayer.SetSource(file.Item1);
FileCurrentlyPlaying = file.Item2;
AppUtils.UpdateListeningHistory(chapterId);
UiClients.ForEach(x => x.OnSurahPlayed(chapterId));
void InitMediaPlayer() {
mediaPlayer = new MyMediaPlayer {IsLoopingEnabled = false};
// the app continues even though I'm explicitly
// throwing this exception for debugging purposes
throw new NullReferenceException();
playerTimer = new MyTimer(1_000); // the actual exception occurs inside this constructor
playerTimer.Start();
UiClients.ForEach(x => x.OnPlayerInitialized());
}
// ...
}
Когда я вызываю метод TryPlayElseStop, должно возникать исключение NullReferenceException.Тем не менее, приложение не вызывает его, а просто продолжает работать, как будто ничего не происходит.
Я попытался отладить его, но как только я перехожу через строку, где должно быть выдано исключение, отладка останавливается, чтоэто то, что я ожидаюТем не менее, приложение не останавливается.Только отладчик.