By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,216 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,216 IT Pros & Developers. It's quick & easy.

Catching ConfigurationException when the config file is corrupted

P: n/a
My application starts with:

Module mmcMain
Public Sub Main()
Debug.WriteLine("Main begin")

Dim splashForm As New mcDlgs.cmcDlgSplash2
splashForm.Show()
....

Accidently I corrapted my config file (missing quote sign -> not valid
xml file) and I got unHandled Exception. Since my real users might also
do the same, I decided to handle this exception.

The information I had is:
An unhandled exception of type
'System.Configuration.ConfigurationException' occurred in system.dll
Additional information: The '"' character, hexadecimal value 0x22,
cannot be included in a name. Line 82, position 34.

Call Stack:

system.dll!System.Configuration.ConfigurationSetti ngs.SetConfigurationSy
stem(System.Configuration.IConfigurationSystem configSystem) + 0x74
bytes

system.dll!System.Configuration.ConfigurationSetti ngs.GetConfig(string
sectionName) + 0x80 bytes

system.dll!System.Diagnostics.DiagnosticsConfigura tion.GetConfigTable()
+ 0xe bytes
system.dll!System.Diagnostics.DiagnosticsConfigura tion.Initialize()
+ 0x80 bytes

system.dll!System.Diagnostics.DiagnosticsConfigura tion.get_IndentSize()
+ 0x7 bytes
system.dll!System.Diagnostics.TraceInternal.Initia lizeSettings() +
0x34 bytes
system.dll!System.Diagnostics.TraceInternal.get_Li steners() + 0x1b
bytes
system.dll!System.Diagnostics.TraceInternal.WriteL ine(string
message) + 0x35 bytes
system.dll!System.Diagnostics.Debug.WriteLine(stri ng message) + 0x6
bytes
mc2.exe!Synergix.mc.mmcMain.Main() Line 13 + 0xc bytes Basic


so I added some code at the begginning of my Main():

Module mmcMain
Public Sub Main()

Try
Dim testStr As String =
System.Configuration.ConfigurationSettings.AppSett ings("testStr")
Catch ex1 As System.Configuration.ConfigurationException
Dim strTitle As String = "MC2 Configuration Exception"
Dim strText As String = "Default values will be used." &
ControlChars.NewLine & ex1.ToString()
ShowMyDialog(strTitle, strText)
Catch ex As Exception
Dim strTitle As String = "other Exception"
Dim strText As String = ex.ToString()
ShowMyDialog(strTitle, strText)
End Try

' Debug.WriteLine("Main begin")

Dim splashForm As New mcDlgs.cmcDlgSplash2
splashForm.Show()
....
At the beginning I commented out the 'Debug.WriteLine' line to get all
my application functions that should catch the ConfigurationException,
but now, even if I do not comment out the "Debug" line, it does not
throw any exceptions.

To sum-up:

1) If I comment out the 'Try' block - the "Debug" throws exception. I
can understand that though there should be a simple way to handle it.
(How about .Net internal error handler "config file is corrupted" ???)

2) If I have the 'Try' block - the "Debug" does not throw exception,
(and I can see its output in the output window). Though the "Debug" line
is outside the Try block. Can you explain why does not it throw
exception?

3) Do you have any other ideas to handle the exceptions of corrupted
config file?

Thanks
Atara.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Anyone ?

Am I the only one that accidetly corrupted my config file?

How do you handle such situation in the real world were users that are
not familiar with xml have to change your well-formed .config files?

Thanks.
Atara


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.