How to I get the exception message as string in GUI

Gary Herron gherron at
Thu Dec 4 10:17:25 CET 2003

On Thursday 04 December 2003 01:01 am, fowlertrainer at wrote:
> Hello ,
>   I want to get the exception error msg in string, but I don't want to
>   save to file, or print.
>   I want to show it in memo.
>   How to I do it ?
>         gd=GTMain.GameDatas
>         s=self.Msg
>         log="Log:\nStart loading"
>         s.SetLabel(log)
>         try:
>             gd.LoadGamesDatas()
>             log=log+"\nGame datas succesfully loaded."
>         except:
>             import traceback
>             traceback.print_exc()   <--------- what I must write ?
>             log=log+"\An error occured while loading !"
>         s.SetLabel(log)
> Thanx.
> --
> Best regards,
>  fowlertrainer                          mailto:fowlertrainer at

The manual is your friend.  From the man page for traceback you can
find a number of things you might want here including these four:


  Given a list of tuples as returned by extract_tb() or
  extract_stack(), return a list of strings ready for printing. Each
  string in the resulting list corresponds to the item with the same
  index in the argument list. Each string ends in a newline; the
  strings may contain internal newlines as well, for those items whose
  source text line is not None.

format_exception_only(type, value)

  Format the exception part of a traceback. The arguments are the
  exception type and value such as given by sys.last_type and
  sys.last_value. The return value is a list of strings, each ending
  in a newline. Normally, the list contains a single string; however,
  for SyntaxError exceptions, it contains several lines that (when
  printed) display detailed information about where the syntax error
  occurred. The message indicating which exception occurred is the
  always last string in the list.

format_exception(type, value, tb[, limit])

  Format a stack trace and the exception information. The arguments
  have the same meaning as the corresponding arguments to
  print_exception(). The return value is a list of strings, each
  ending in a newline and some containing internal newlines. When
  these lines are concatenated and printed, exactly the same text is
  printed as does print_exception().

format_tb(tb[, limit])

  A shorthand for format_list(extract_tb(tb, limit)).

Gary Herron

More information about the Python-list mailing list