Solved

customErrors mode for window application

Posted on 2014-01-23
8
440 Views
Last Modified: 2014-01-24
Hi Experts,

In web application, inside web.config, we can modify the <customErrors mode="On/Off/remote"> to our need.
Is there a similar method in app.config in window application as well that we can choose to either let the original error message come up for debugging when an unhandled exception occurred or replace it with a customize error message when the application is released.

Thanks
0
Comment
Question by:LoGa1234567890
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:ktaczala
ID: 39802592
add this to application events

#If DEBUG Then
        'do something like messagebox.show("Debugging code message")
#Else
        'do something else like write to log
#End If
0
 

Author Comment

by:LoGa1234567890
ID: 39805531
Hi Ktaczala,

Sorry for the late response !
What is the # in your code mean ?
I take the # off and paste the code:

If DEBUG Then
       messagebox.show("Debugging code message")
Else
        'do something else like write to log
End If

in MyApplication_Startup for a try.
The Debug was then curvy underlined by text editor with the comment 'Debug is a type and can't be used as an expression'.

Do you have an example for my question above.
My application run smoothly in developer machine and in many user machines, but in one xp machine, due to a dll can't be found, that caused unhandled exception to occur, see picture.
unhandled-exception.JPG
0
 
LVL 12

Expert Comment

by:ktaczala
ID: 39805598
keep those # signs in the code
here's a link that explains more about this code:
http://stackoverflow.com/questions/6912273/if-debug-is-ignored-vb-net-or-c

If you click the details button on the error above.  What info does that show?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:LoGa1234567890
ID: 39805677
Hi Ktaczala,
I put :
#If CONFIG = "Debug" Then
#Const DEBUG = True
#ElseIf CONFIG = "Release" Then
#CONST DEBUG = false
#End If
in Sub MyApplication_Startup, the code was ignored when start up.

The code inside the button:
-------------------------------------------------
Detail error:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ComponentModel.Win32Exception: The system cannot find the file specified
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start(String fileName)
   at LopsWin.LogOut.tmAnimater_Tick(Object sender, EventArgs e)
   at System.Windows.Forms.Timer.OnTick(EventArgs e)
   at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3649 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
MC
    Assembly Version: 3.0.0.0
    Win32 Version: 2.0.50727.3649 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/mscorlib/2.0.0.0__b77a5c561934e089/mscorlib.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3645 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3644 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3644 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
›–‹›¿‰¿‹‘†—š‡
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3649 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/mscorlib/2.0.0.0__b77a5c561934e089/mscorlib.dll
----------------------------------------
License
    Assembly Version: 1.0.0.0
    Win32 Version: 2.0.50727.3649 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/mscorlib/2.0.0.0__b77a5c561934e089/mscorlib.dll
----------------------------------------
Lopwin
    Assembly Version: 1.0.0.0
    Win32 Version: 2.0.50727.3649 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/mscorlib/2.0.0.0__b77a5c561934e089/mscorlib.dll
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 8.0.0.0
    Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Core
    Assembly Version: 3.5.0.0
    Win32 Version: 3.5.30729.1 built by: SP
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
CustomMarshalers
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/CustomMarshalers/2.0.0.0__b03f5f7f11d50a3a/CustomMarshalers.dll
----------------------------------------
System.Web.Services
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Services/2.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3654 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3654 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Design
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3645 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Design/2.0.0.0__b03f5f7f11d50a3a/System.Design.dll
----------------------------------------
xlt8c1n5
    Assembly Version: 0.0.0.0
    Win32 Version: 2.0.50727.3644 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
eoinn5v4
    Assembly Version: 0.0.0.0
    Win32 Version: 2.0.50727.3644 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
x0errdsh
    Assembly Version: 0.0.0.0
    Win32 Version: 2.0.50727.3644 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
acjw5mwy
    Assembly Version: 0.0.0.0
    Win32 Version: 2.0.50727.3644 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
Microsoft.VisualBasic.PowerPacks
    Assembly Version: 9.0.0.0
    Win32 Version: 3.0.30214.0
    CodeBase: file:///C:/Documents%20and%20Settings/All%20Users/Documents/Loptions/Microsoft.VisualBasic.PowerPacks.DLL
----------------------------------------
Accessibility
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
l1xnpfma
    Assembly Version: 0.0.0.0
    Win32 Version: 2.0.50727.3644 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
msmkeatg
    Assembly Version: 0.0.0.0
    Win32 Version: 2.0.50727.3644 (GDR.050727-3600)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
---------------------------------------------------------
I put the mscorlib.dll inside the folder where my app is, the error is gone in that user computer. I overlooked the last section:
<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>
Now I am trying it out.
0
 
LVL 12

Accepted Solution

by:
ktaczala earned 350 total points
ID: 39805807
Ok, couple of things to do.
1.) put this in your place of choice:

#If DEBUG Then
        MsgBox("Debug")
#Else
        MsgBox("Release")
#End If

2.)
Click Build | Configuration Manager and select "Release" in <Active Solution Configuration>
Click Close
Click Build | Build Solution
Now run it. (F5)
To get back to "Debug"repeat steps only select "Debug" in <Active Solution Configuration>
0
 

Author Comment

by:LoGa1234567890
ID: 39806038
Hi Ktaczala,

I can switch between debug & release with that method, but the message is wrong.
If i swap the message box to:

#If DEBUG Then
    MsgBox("Release")
#Else
        MsgBox("Debug")
#End If
then the message is correct.

Why is that ?
Is "#If DEBUG Then" == "#If DEBUG = false Then"
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39806190
Above is relevant if you are handling an exception yourself and want to show different messages depending on build type. If you want to show a custom message for unhandled exceptions, see the example here for global exception handler

http://richnewman.wordpress.com/2007/04/08/top-level-exception-handling-in-windows-forms-applications-part-1/
0
 
LVL 12

Expert Comment

by:ktaczala
ID: 39806866
change the state of the "Define DEBUG Constant"  under Compile | Advanced Compile Options.
What is happening is when you change from debug to release it toggles that checkbox.

I also found out all you need to do is toggle that checkbox and your code will switch between debug and release.  You don't have to do the other steps. :)
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question