Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2008 by Ivor Horton; ISBN: 9780470225905
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2010, 03:36 AM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unhandled exception

I was trying the expression Int32::Parse(in Page 107) in C++/CLI console program, however before I input an integer the system reminds that(in the command windows): Unhandled excepion: System.FormatExceprion....ect.
Below is my code:

//Calculating the price of carpet
#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
char ch = Console::Read();
Console::WriteLine(L"The character is:{0}",ch); //Why these two things
// //putting together
Console::Write(L"Enter an integer:"); //cause error???
int value = Int32::Parse(Console::ReadLine());
Console::WriteLine(L"You entered:{0}",value);

return 0;
}
Please give your help, thanks!

Last edited by frankgt40; October 5th, 2010 at 03:51 AM..
 
Old October 6th, 2010, 08:22 AM
Authorized User
 
Join Date: Feb 2010
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default response

I have encountered this also. My understanding is that after the first read is finished, a '\n' will remain in the input buffer. This creates a problem for the ReadLine, and results in the exception. A scheme for dealing with that is:

Code:
// p2p_question_5oct2010.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"Hello World");


	char ch = Console::Read();
	Console::WriteLine(L"The character is:{0}",ch); //Why these two things
                                                                        //putting together 
	for(int i = 0; i<10; i++)	// flush input buffer
	{
		if( Console::Read() == '\n')
			break;
	}

	Console::Write(L"Enter an integer:");              //cause error???
	int value = Int32::Parse(Console::ReadLine());
	Console::WriteLine(L"You entered:{0}",value);

    return 0;
}
This runs without the exception. See http://www.daniweb.com/forums/thread301503.html for additional information.
 
Old October 7th, 2010, 07:00 AM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks a lot!

Thanks a lot!





Similar Threads
Thread Thread Starter Forum Replies Last Post
unhandled exception dipakp ASP.NET 2.0 Professional 1 July 6th, 2007 02:16 PM
Unhandled NullReference Exception dheeraj1053 C# 1 May 30th, 2006 05:55 PM
Unhandled NullReference Exception MAKO C# 1 April 19th, 2006 05:46 AM
Unhandled Exception stu9820 ASP.NET 1.0 and 1.1 Basics 11 January 14th, 2004 05:55 PM
Unhandled Exception: mbarrett C# 3 August 1st, 2003 05:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.