?
Solved

exception handling

Posted on 2009-06-27
5
Medium Priority
?
196 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 200 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 1000 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 800 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

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