Python3 exception handling <p>I'm trying to make a simple program (for learning purposes) using exception handling. What I'm trying to do is:</p> <pre><code>try: x = int(input()) except ValueError as var: # HERE I WANT TO USE THE 'x' STRING VALUE </code></pre> <p>I know about the the various ways to use the <strong>exception message</strong> (for instance by using <code>str(var)</code>).</p> <p>For example, if the input is <code>bla</code> which would cause a ValueError exception, <code>print(var)</code> outputs <code>invalid literal for int() with base 10: 'bla'</code>, which is not really usable. </p> <p>However, I created this program that should use <code>str(var)</code> to my advantage:</p> <pre><code>try: x = int(input()) except ValueError as var: s = str(var) print('Exception message: ' +s) i=0 while (s[i] != '\''): i = i+1 i = i+1 print_str = '' while (s[i] != '\''): print_str = print_str + str(s[i]) i++ print('print_str = ' + print_str) </code></pre> <p>This program would probably work after a few changes..</p> <p>So my question is: Is there a more direct way to get the 'x' string value?</p>