Solved

exception handling

Posted on 2009-06-27
5
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

733 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