Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: opinions: how to handle resource errors?  (Read 9598 times)

0 Members and 1 Guest are viewing this topic.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: opinions: how to handle resource errors?
« Reply #15 on: November 10, 2013, 07:13:07 pm »
Writing to a non-existent console or a log file the user doesn't know about doesn't answer the question because the user still has no idea what happened =P  As you just saw, eXpl0it3r had no idea there was a log file, because Zloxx didn't tell him about it.  If you happen to know of a platform-agnostic way to open the log file automatically from C++ code, then it can be a valid solution.

I'm pretty sure there is no good platform-agnostic way of visually reporting *all* errors, including font loading failure.  I also ended up deciding I have no real choice besides MessageBox() on Windows, and someday I'll figure out what the equivalent Mac/Linux functions are for that (maybe system() is part of it?).  Every OS with a GUI has error popup windows so I'm sure it's doable.

Personally, even if I get fonts loaded, I don't want to report fatal error messages using them because that would be writing a hell of a lot of code (which probably has bugs!) for something the OS already has implemented anyway.  We always want our programs to look "native," after all, since that conforms with user expectations better.  MessageBox() looks far better and is more intuitive than anything I could've drawn with SFML.

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: opinions: how to handle resource errors?
« Reply #16 on: November 10, 2013, 07:34:10 pm »
I was going to mention that writing to a log file is always an available option, but then I saw that Ixrec explained why that's not a great option.

It's not all that hard to open the log-file, but doing so in a platform-agnostic way is probably impossible (unless you're not supporting Linux). The basic idea would be executing a command (as system() does, though that's not the way I'd recommend doing it). On Windows it would be "notepad errorlog.txt", on Mac you'd run "open -a TextEdit errorlog.txt" (though this isn't working when I try it for some reason), and on Linux... well, I doubt you can assume any specific text editor is installed, unfortunately.

The proper way to execute a command is the exec* family of functions on Mac and Linux (execlp is probably the simplest choice in this situation). On Windows I think there's an equivalent (maybe something like ExecuteProcess?), but I'm not sure what it is.

If you prefer actual popup dialogs, the equivalent of MessageBox on Mac appears to be CFUserNotification, though it looks rather more complicated. On Linux, perhaps Zenity would work (in which case you'd probably call it with execlp); I'm not sure if there's a system call that makes a popup dialog.

Haze

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Github Profile
Re: opinions: how to handle resource errors?
« Reply #17 on: December 14, 2013, 09:01:08 am »
Regarding the questions from the two previous posters about displaying a MessageBox in Linux:

Zenity looks better as it uses the native desktop theme, but it may not be available on all systems.
zenity --text="Bad news" --error

There is also xmessage, which is a X11 app provided with the X11 server, so you can safely assume it's available:
xmessage "Bad news"

and on Linux... well, I doubt you can assume any specific text editor is installed, unfortunately.
xedit will do the job! (it's another X11 app).


 

anything