
- #Python in visual studio try except not working how to
- #Python in visual studio try except not working full
Print('F = %s, C %s. Print("C = %s, F %s." % (celsius, fahrenheit))įahrenheit = get_input('Enter value in Fahrenheit: ', convert_to='float') import sysĬelsius = get_input('Enter value in Celsius: ', convert_to='float') Not sure what is wrong for you now, ideally you should create a new question, as your new question is beyond the scope of your original question, but I prepared a quick, more slightly structured example based on your code. This also applies to the similar code you have for Celsius and Fahrenheit. You could achieve this by something similar to this. You would also need to change the print statement inside the exception handling to properly handle a potential None value from Options. So that the code that handles the initial exception is throwing a new exception. The reason for this is because int(input(.)) raises an exception before Option is defined. If you add Option = None before try the code should execute properly. This basically puts it outside the try catch scenario. The exception is thrown after you caught an exception. (y/n): ') try: if userInput 'y': print('Here we go ') print() elif userInput 'n': print('Too bad we're starting anyways') else: raise ValueError('What's up with that') except: print('Wrong Input Try Again') As suggested by ctrl-alt-delor you can also skip the try/except block and only use an if/else block. ValueError: invalid literal for int() with base 10: 'wad'ĭuring handling of the above exception, another exception occurred:įile "C:\Users\user\Documents\Visual Studio 2015\Projects\TempConversion\TempConversion\TempConversion.py", line 11, in

#Python in visual studio try except not working full
The full traceback, when inputting the value "wad" in the first screen: Traceback (most recent call last):įile "C:\Users\user\Documents\Visual Studio 2015\Projects\TempConversion\TempConversion\TempConversion.py", line 7, in Convert FAHRENHEIT to CELSIUS.")Ĭelsius = float(input("Enter value in Celsius: "))įahrenheit = float(input("Enter value in Fahrenheit: "))

Summarised, it seems like Python is ignoring the except clauses in the source code.
#Python in visual studio try except not working how to
I'm currently trying to learn how to program in Python (3.5) and I've had a problem with a conversion program.
