Exception Handler

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ich_will

Exception Handler

Post by ich_will »

What should I do if an exception occurs?
For Example the Div by Zero exception, at the moment my function prints out a message and holds, but I think thats a really bad solution.
Tim

Re:Exception Handler

Post by Tim »

Depends on the exception. Some exceptions (e.g. page fault) can be corrected and the app can continue. Others (e.g. divide by zero) indicate and error, and the app should exit.
ich_will

Re:Exception Handler

Post by ich_will »

But I can't close the Kernel if there's an div by zero exception, or should i.
Tim

Re:Exception Handler

Post by Tim »

How can the kernel handle a fatal error in its own code? If the kernel has a fatal error (i.e. a bug), the only thing to do is print as much information about the exception as is available, and halt the system.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Exception Handler

Post by Candy »

Tim Robinson wrote: How can the kernel handle a fatal error in its own code?
For some cases you might be able to code something :)

For instance, when you call INVLPG on a 386 you get an invalid opcode exception. If you define the invlpg instruction to take an X number of bytes (possibly some more, maybe with a zero operand with it?) and you can runtime replace it with a different code sequence (the cr3 reload sequence) you could use the same code for both computers without slowing them down, by using (not even abusing) the invalid opcode mechanism.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Exception Handler

Post by Pype.Clicker »

iirc, the Intel Manual (section about exceptions) gives hints on how exceptions should be handled. In the case of a kernel, as the same piece of code generated an exception and tries to handle it, things may sometimes be a little different.

For instance, you might try to have "resume points" where the execution should be transferred in case of an "expected" exception, but just entering a "panic mode" on unrecoverable errors (that is, errors that come from kernel itself rather than from some user-level call) would probably a more realistic target.
Post Reply