Skip to content
Browse files

Added an unhandled exception catching window.

  • Loading branch information...
1 parent 196ca8d commit 871c0fda34afb178950cc0237790fea1a1d974a5 @Amrykid committed May 5, 2012
View
7 src/Hanasu/Hanasu.csproj
@@ -126,6 +126,9 @@
<Compile Include="Services\Stations\Station.cs" />
<Compile Include="Services\Stations\StationsService.cs" />
<Compile Include="Services\Stations\StationsServiceStatus.cs" />
+ <Compile Include="Windows\ErrorWindow.xaml.cs">
+ <DependentUpon>ErrorWindow.xaml</DependentUpon>
+ </Compile>
<Compile Include="Windows\SettingsWindow.xaml.cs">
<DependentUpon>SettingsWindow.xaml</DependentUpon>
</Compile>
@@ -156,6 +159,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
+ <Page Include="Windows\ErrorWindow.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="Windows\SettingsWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
View
23 src/Hanasu/MainWindow.xaml.cs
@@ -40,6 +40,8 @@ public MainWindow()
//Hanasu.Services.Friends.FriendsService.Initialize();
+ Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
+
this.KeyUp += MainWindow_KeyUp;
this.Loaded += MainWindow_Loaded;
@@ -50,6 +52,27 @@ public MainWindow()
//Is in the designer. Do nothing.
}
}
+
+ void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
+ {
+ e.Handled = true;
+
+ ErrorWindow ew = new ErrorWindow();
+ ew.DataContext = e.Exception;
+
+ try
+ {
+ ew.Owner = this;
+
+ ew.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
+ }
+ catch (Exception)
+ {
+ ew.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
+ }
+
+ ew.ShowDialog();
+ }
private static Hanasu.External.InterceptKeys.LowLevelKeyboardProc keyHookproc = null;
private void HandleMediaKeyHooks()
{
View
4 src/Hanasu/Properties/AssemblyInfo.cs
@@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.281.0")]
-[assembly: AssemblyFileVersion("1.0.281.0")]
+[assembly: AssemblyVersion("1.0.285.0")]
+[assembly: AssemblyFileVersion("1.0.285.0")]
View
27 src/Hanasu/Windows/ErrorWindow.xaml
@@ -0,0 +1,27 @@
+<metro:MetroWindow x:Class="Hanasu.Windows.ErrorWindow"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:metro="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
+ Title="Uh Oh!" Height="329" Width="525" ResizeMode="NoResize">
+ <Window.Resources>
+ <ResourceDictionary>
+ <ResourceDictionary.MergedDictionaries>
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/Hanasu;component/Icons.xaml" />
+ <!-- From MahApps.Metro.Resources package-->
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Red.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
+ </ResourceDictionary.MergedDictionaries>
+ </ResourceDictionary>
+ </Window.Resources>
+ <Grid>
+ <Label Content="Something bad happened!" Height="69" Margin="26,10,45,0" FontSize="25" Name="label1" VerticalAlignment="Top" />
+ <Label Content="Please contact Amrykid with the following data." Height="28" FontSize="16" Margin="66,51,57,0" Name="label2" VerticalAlignment="Top" />
+ <TextBlock Height="148" Margin="32,98,0,0" Name="textBlock1" Text="{Binding}" VerticalAlignment="Top" HorizontalAlignment="Left" Width="442" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" />
+ <Button Content="Copy" Height="23" Margin="26,0,0,12" Name="button1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="75" Click="button1_Click" />
+ <Button Content="Close" Height="23" HorizontalAlignment="Right" Margin="0,0,16,8" Name="button2" VerticalAlignment="Bottom" Width="75" Click="button2_Click" />
+ </Grid>
+</metro:MetroWindow>
View
38 src/Hanasu/Windows/ErrorWindow.xaml.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using MahApps.Metro.Controls;
+
+namespace Hanasu.Windows
+{
+ /// <summary>
+ /// Interaction logic for ErrorWindow.xaml
+ /// </summary>
+ public partial class ErrorWindow : MetroWindow
+ {
+ public ErrorWindow()
+ {
+ InitializeComponent();
+ }
+
+ private void button1_Click(object sender, RoutedEventArgs e)
+ {
+ Clipboard.SetText(textBlock1.Text, TextDataFormat.Text);
+ }
+
+ private void button2_Click(object sender, RoutedEventArgs e)
+ {
+ this.DialogResult = true;
+ this.Close();
+ }
+ }
+}

0 comments on commit 871c0fd

Please sign in to comment.
Something went wrong with that request. Please try again.