I'm trying to catch a thrown Exception, but it doesn't bubble up to where it was called. It breaks in InsertNewUser
's catch block, saying
"An exception of type 'System.Exception' occurred in PeakPOS.exe but was not handled in user code"
If I click on debugger Continue, it goes to some file called App.g.i.cs
and breaks on a line I don't understand but has something to do with debugging on break. The application terminates after that.
Why is it saying the exception is unhandled when it is being rethrown and then re-caught and handled (to-be handled)?
AccessViewModel.cs
public void SaveNewUser(Popup popup)
{
UserAccounts.Add(TempUser);
string salt = PeakCrypto.GenerateSalt();
string hash = PeakCrypto.GenerateHashedPassword(Password + salt);
try
{
PeakDB.InsertNewUser(TempUser, salt, hash);
}
catch (Exception e)
{
//TODO notify user that new account could not be saved
}
CreateNewAccount();
if (popup != null)
popup.IsOpen = false;
}
PeakDB.cs
public static async void InsertNewUser(UserAccount user, String salt, String hash)
{
var db = await DatabaseHelper.GetDatabaseAsync();
try
{
using (var userStatement = await db.PrepareStatementAsync(
"INSERT INTO AccessAccounts (FirstName, LastName, Salt, Hash) VALUES(@first, @last, @salt, @hash)"))
{
userStatement.BindTextParameterWithName("@first", user.FirstName);
userStatement.BindTextParameterWithName("@last", user.LastName);
userStatement.BindTextParameterWithName("@salt", salt);
userStatement.BindTextParameterWithName("@hash", hash);
await userStatement.StepAsync();
}
}
catch(Exception e)
{
// TODO: log the exception error
throw;
}
}
App.g.i.cs
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif