Solved

exception handling

Posted on 2009-06-27
5
191 Views
Last Modified: 2013-12-14
I am using visual studio 2008 - C#
I am trying to use code with ex.Message
intellisense does not recognize ex - I see exception
Should I be able to use ex as code in C#?
thank you
0
Comment
Question by:davetough
5 Comments
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 50 total points
ID: 24727405
can you share your code
0
 

Author Comment

by:davetough
ID: 24727431
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace labOne
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int myTotal = Int16.Parse(textBox1.Text);
            }
            catch
            {
                MessageBox.Show("error":, ex.Message");
            }

        }
    }
}
0
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 250 total points
ID: 24727443
catch (Exception ex)
0
 

Author Comment

by:davetough
ID: 24727465
if i understand correctly - i insert it here
  try
            {
                int myTotal = Int16.Parse(textBox1.Text);
            }
            catch (Exception ex)  //HERE

            {
                MessageBox.Show("error":, ex.Message");                 }
0
 
LVL 11

Assisted Solution

by:saragani
saragani earned 200 total points
ID: 24727712
You understand correctly.

You can also catch by exception type:

            try
            {
                int myTotal = Int16.Parse(textBox1.Text);
            }
            catch (IOException ex)
            {
                MessageBox.Show("error":, ex.Message");
            }
            catch (UserDesignedException ex)
            {
                MessageBox.Show("error":, ex.Message");
                // Do some code here if you need
            }
            catch (Exception ex)
            {
                MessageBox.Show("error":, ex.Message");
            }
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

911 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

17 Experts available now in Live!

Get 1:1 Help Now