in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

Symbian os Expleined effective C++ programming for smartphones - Batchelor D.

Batchelor D. Symbian os Expleined effective C++ programming for smartphones - Wiley publishing , 2005. - 394 p.
ISBN 0-470-02130-6
Download (direct link): symbianosexpltivec++2005.pdf
Previous << 1 .. 100 101 102 103 104 105 < 106 > 107 108 109 110 111 112 .. 151 >> Next

Panics on EKA1
Panics on EKA2
process.2 The panic functions take a panic category string, which can contain an unlimited number of characters, and an error code, expressed, as usual, as a Tint.
15.2 Good Panic Style
Even without breaking into the debugger, you should still be able to track down the cause of a panic using the panic category string and error number. It's good style to make your panic category string descriptive and unique, so other developers can locate the string in your header files, and with it, any associated panic error codes (which should also have suitably descriptive names).
Thus, you might have a general panic header file for your library which includes the following:
// ClangerPanic.h
#ifndef CLANGERPANIC_H____
#define CLANGERPANIC_H____
#include <e32base.h>
_LIT(KClangerPanic, "CLANGER-ENGINE");
enum TClangerEnginePanic {
ECorruptBlueStringPudding, // =0,
EIronChickenNotInitialized,// =1,
EInvalidClangerSetting // =2
static void Panic(TClangerEnginePanic aCategory);
#endif // CLANGERPANIC_H_____
Which defines the Panic() function separately as follows:
static void Panic(TClangerEnginePanic aCategory)
User::Panic(KClangerPanic, aCategory);
(You'll notice by the way that the panic enumeration is a T Class because an enumeration is a type. Chapter 1 discusses the differences between class types on Symbian OS and how to use them.)
When the library code is passed invalid arguments, it may invoke Panic() with the appropriate error code, resulting in a panic and
2 Except where a server thread uses RMessagePtr to panic a misbehaving client thread.
termination of the thread in which it is running. The category and error will be reported, and maythen be traced back by searching the library's header files for "CLANGER-ENGINE", located inside ClangerPanic.h. You'll see I've commented each error's enum value with its associated number, just to make the lookup easier. I've tried to give each a descriptive name, though obviously they could be further documented, using in-source comments, for clarity.
Of course, if a client programmer has access to the source code for clanger.dll, they can also search it for calls to Panic() which use a particular error value, to track down where a panic originated.
15.3 Symbian OS Panic Categories
Symbian OS itself has a series of well-documented panic categories and associated error values. You can find details of platform-specific panics in your preferred SDK. From Symbian OS v7.0, there is a special Panics section in the C++ API Reference of each SDK, which contains a comprehensive list of the Symbian OS system panics. Typical values you may encounter include:
• KERN-EXEC 3 - raised by an unhandled exception (such as an access violation caused, for example, by dereferencing NULL, memory misalignment or execution of an invalid instruction) inside a system call to the kernel executive; if an unhandled exception occurs inside code which is instead executing in user mode, the panic is seen as USER-EXEC 3
• E3 2USER-CBASE 46 - raised by the active scheduler as a result of a stray signal (described further in Chapters 8 and 9)
• E3 2USER-CBASE 90 - raised by the cleanup stack when the object specified to be popped off is not the next object on the stack. The following code illustrates the cause of the panic; this issue is described more fully in Chapter 3, which describes the cleanup stack.
class CExample; // defined elsewhere
void CauseAPanicL()
Tint val = 1;
CExample* ptrl = new (ELeave) CExample();
CExample* ptr2 = new (ELeave) CExample();
CleanupStack::Pop(ptr1); // Panics with E32USER-CBASE 90 here.
CleanupStack::Pop(ptr2); // the code never gets here }
As a user, if making the chess move you've carefully worked out causes your game to panic and close, you're probably not interested in the category or error code. Such precise details are irrelevant and the "program closed" dialog is more irritating than helpful.
15.4 Panicking Another Thread
I've shown how to call User::Panic() when you want the thread to panic itself. But how, and when, should you use RThread::Panic() ? As I described earlier, the RThread::Panic() function can be used to kill another thread and indicate that the thread had a programming error. Typically this is used by a server to panic a client thread when the client passes a badly-formed request. You can think of it as server self-defense; rather than go ahead and attempt to read or write to a bad descriptor, the server handles the client's programming error gracefully by panicking the client thread. It is left in a good state which it would not have been if it had just attempted to use the bad descriptor. Generally, in a case like this, the malformed client request has occurred because of a bug in the client code, but this strategy also protects against more malicious "denial of service" attacks in which a client may deliberately pass a badly-formed or unrecognized request to a server to try to crash it. The Symbian OS client-server architecture is discussed in Chapters 11 and 12; the latter chapter includes sample code that illustrates how a server can panic its client.
Previous << 1 .. 100 101 102 103 104 105 < 106 > 107 108 109 110 111 112 .. 151 >> Next