0

C# need help, formatException unhandled.

hey community! I am having an issue with my coding. can someone explain to me what am i doing wrong or what does it mean formatException unhandled. Please, trying to dumb it down for me to understand. I am using visual studio community 2015 here's my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GenerteRndNumAndAccept { class Program { static void Main(string[] args) { bool displayMenu = true; while (displayMenu) { displayQuestion(); } Console.Read(); } public static void displayQuestion() { Random random = new Random(); int x = random.Next(100); Console.WriteLine("please enter this number: " + x); int inputAnswer = Convert.ToInt16(Console.Read()); int y = inputAnswer; if (y == x) { Console.WriteLine("You're correct!"); Console.WriteLine("Enter to continue:"); } else { Console.WriteLine("You're not correct!"); Console.WriteLine("Enter to continue:"); } Console.Read(); } } }

8th Dec 2016, 10:02 PM
Sebastien Pham
Sebastien Pham - avatar
6 Respuestas
+ 1
Here's an example of a multiple catch handlers one after the other such as the following example: try { int leftHandSide = int.Parse(lhs()Operand.Text); int rightHandSideSide = int.Parse(rhsOperand.Text); int answer = doCalculation(leftHandSide, rightHandSideSide); result.Text = answer.ToString(); } catch (FormatException fEx) { // ... } catch (OverflowException oEx) { //... } If the code in the try block throws a FormatException exception, the statements in the catch block for the FormatException exception run. If the code throws at OverflowException exception, the catch block for the OverflowException exception runs. Another resource is at Microsoft Library on handling exceptions: https://msdn.microsoft.com/en-us/library/ms173162.aspx
9th Dec 2016, 4:00 AM
Gena Beamon
Gena Beamon - avatar
0
unhandled exceptions: You can easily examine exceptions generated by your application. If you are running the application in Microsoft Visual Studio 2015 and debug mode (that is, on the Debug menu you can select Start Debugging to run the application) and an exception occurs. a dialog box will appear in the application pauses, helping you determine the cause of the exception. The application stops at the statement that caused the exception, and you drop into the debugger. You can examine the values of variables you can change the values of variables and you can step through your code from point at which the exception occurred by using the debug toolbar and the various debug windows.
9th Dec 2016, 1:27 AM
Gena Beamon
Gena Beamon - avatar
0
Get free e-books from Microsoft Press: www.Microsoftvirtualacademy.com/e-books Look for great resources at Microsoft Virtual Academy where you can learn new skills and help Advance your career with free Microsoft training developed by experts, & overviews to drilldowns on special topics. in addition 2 year unhandled exception try cold and catching exceptions
9th Dec 2016, 1:39 AM
Gena Beamon
Gena Beamon - avatar
0
Trying code and catching exceptions (John Sharp, Microsoft Visual C# Step by Step, 8th Edition): t-shirt (#) makes it easy to separate the error-handling code from the code that implements the primary logic of a program by using exceptions and exception handlers. To write exception-aware programs you need to do two things: 1. Write your code within a try block (try is C Sharp key word). When the code runs it attempts to execute all the statements in a try block, and if none of these statements generate an exception, they all run, one after the other, to completion. However, if an error code occurs exception jumps out of the try block and into another piece of code designed and handle the exception--a catch handler. 2. Write one or more catch handlers (catch is another C sharp keyword) immediately after the try block to handle any possible errors conditions. A catch Handler is intended to capture and handle a specific type of exception, and you can have multiple catch handlers after a try block, each one designed to trap and process a specific exception. This enables you to provide different handlers for the different errors that could arise in the try block. If any of the statements within a try block causes an error, the run time throws an exception. The runtime then examines the catch handlers after the try block and transfers control directly to the first matching handler.
9th Dec 2016, 2:12 AM
Gena Beamon
Gena Beamon - avatar
0
thanks for the helps but It stilll doesn't help me if I dont know what it means and I only know the fundamentals. if you have an examples that would be helpful.
9th Dec 2016, 2:17 AM
Sebastien Pham
Sebastien Pham - avatar
0
If you only know the fundamentals or don't know the fundamentals a good starter's is pick up the e-book called, "Software Development Fundamentals, Exam 97-361" by Wiley. www.Wiley.com/college/Microsoft Additionally, Microsoft Virtual Academy provides free courses on the fundamentals of SDF.
9th Dec 2016, 6:23 AM
Gena Beamon
Gena Beamon - avatar