Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

exception handling

Posted on 2009-06-27
5
Medium Priority
?
198 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

Independent Software Vendors: 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!

Question has a verified solution.

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

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

610 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