Solved

customErrors mode for window application

Posted on 2014-01-23
8
427 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:LoGa1234567890
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 12

Accepted Solution

by:
ktaczala earned 350 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now