Results 1 to 10 of 10
  1. #1
    lakshmancb is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default How to Fix dispatchUncaughtException in Java

    Hello Sir/ Madam,

    I a m lakshman Cb and new to JAVA.

    I am using a thread (implements runnable format).

    i am calling A private function from run() method.

    in the private method, i created an object of a class.
    while doing "new Class()", dispatchUncaughtException(throwable): is thrown and i am not able to debug the application from that point.

    can anyone help me to sort out the problem.

    Thanks
    Lakshman

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: How to Fix dispatchUncaughtException in Java

    i am calling A private function from run() method.
    Java doesn't have functions. They are methods.

    while doing "new Class()", dispatchUncaughtException(throwable): is thrown
    java.lang.Class has no public constructor, so you are evidently referring to some other class (badly) named Class.
    dispatchUncaughtException isn't in the standard JDK, nor could it be as it doesn't follow the naming convention for class names to start with an uppercase letter.

    You'll have to ask wherever you got those classes, or post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    lakshmancb is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: How to Fix dispatchUncaughtException in Java

    Hello Mr. DB,

    I wrote an example as "Class()".
    Actually, what i meant is while creating object of a class, the exception is occurring nad not able to ccontinue.

    Thanks
    Lakshman

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,873
    Rep Power
    25

    Default Re: How to Fix dispatchUncaughtException in Java

    Please post the full text of the error message without any editing. Copy and paste it here.

  5. #5
    lakshmancb is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: How to Fix dispatchUncaughtException in Java

    Hello Mr. Norm

    Thread.dispatchUncaughtException(Throwable)line : Not available.

    Below "Source not found" message

    Thanks lakshman

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,873
    Rep Power
    25

    Default Re: How to Fix dispatchUncaughtException in Java

    Please post the full text of the error message without any editing.

    Where is the stack trace? Make sure the catch block calls the printStackTrace method.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: How to Fix dispatchUncaughtException in Java

    Quote Originally Posted by lakshmancb View Post
    I wrote an example as "Class()".
    Actually, what i meant is while creating object of a class,
    Quote Originally Posted by lakshmancb View Post
    Thread.dispatchUncaughtException(Throwable)line : Not available.
    You seem to be determined to make it difficult for volunteers here to help you. And where's that SSCCE?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    jasjeet is offline Member
    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Default Re: How to Fix dispatchUncaughtException in Java

    package parser;
    import java.io.*;
    import lexer.*;
    import symbols.*;
    import inter.*;

    public class Parser {

    private Lexer lex; // lexical analyzer for this parser
    private Token look; // lookahead tagen
    Env top = null; // current or top symbol table
    int used = 0; // storage used for declarations

    public Parser(Lexer l) throws IOException {
    lex = l;
    move();
    }

    void move() throws IOException {
    look = lex.scan();
    }

    void error(String s) {
    throw new Error("near line" + Lexer.line + ":" + s);
    }

    void match(int t) throws IOException {
    if (look.tag == t)
    move();
    else
    error("syntax error");
    }

    public void program() throws IOException { // program -> block
    Stmt s = block();
    int begin = s.newlabel();
    int after = s.newlabel();
    s.emitlabel(begin);
    s.gen(begin, after);
    s.emitlabel(after);
    }

    Stmt block() throws IOException { // block -> { decls stmts }
    match('{');
    Env savedEnv = top;
    top = new Env(top);
    decls();
    Stmt s = stmts();
    match('}');
    top = savedEnv;
    return s;
    }

    void decls() throws IOException {

    while (look.tag == Tag.BASIC) { // D -> type ID ;
    Type p = type();
    Token tok = look;
    match(Tag.ID);
    match(';');
    Id id = new Id((Word) tok, p, used);
    top.put(tok, id);
    used = used + p.width;
    }
    }

    Type type() throws IOException {

    Type p = (Type) look; // expect look.tag == Tag.BASIC
    match(Tag.BASIC);
    if (look.tag != '[')
    return p; // T -> basic
    else
    return dims(p); // return array type
    }

    Type dims(Type p) throws IOException {
    match('[');
    Token tok = look;
    match(Tag.NUM);
    match(']');
    if (look.tag == '[')
    p = dims(p);
    return new Array(((Num) tok).value, p);
    }

    Stmt stmts() throws IOException {
    if (look.tag == '}')
    return Stmt.Null;
    else
    return new Seq(stmt(), stmts());
    }

    Stmt stmt() throws IOException {
    Expr x;
    Stmt s1, s2;
    Stmt savedStmt; // save enclosing loop for breaks

    switch (look.tag) {

    case ';':
    move();
    return Stmt.Null;

    case Tag.IF:
    match(Tag.IF);
    match('(');
    x = bool();
    match(')');
    s1 = stmt();
    if (look.tag != Tag.ELSE)
    return new If(x, s1);
    match(Tag.ELSE);
    s2 = stmt();
    return new Else(x, s1, s2);

    case Tag.WHILE:
    While whilenode = new While();
    savedStmt = Stmt.Enclosing;
    Stmt.Enclosing = whilenode;
    match(Tag.WHILE);
    match('(');
    x = bool();
    match(')');
    s1 = stmt();
    whilenode.init(x, s1);
    Stmt.Enclosing = savedStmt; // reset Stmt.Enclosing
    return whilenode;

    case Tag.DO:
    Do donode = new Do();
    savedStmt = Stmt.Enclosing;
    Stmt.Enclosing = donode;
    match(Tag.DO);
    s1 = stmt();
    match(Tag.WHILE);
    match('(');
    x = bool();
    match(')');
    match(';');
    donode.init(s1, x);
    Stmt.Enclosing = savedStmt; // reset Stmt.Enclosing
    return donode;

    case Tag.BREAK:
    match(Tag.BREAK);
    match(';');
    return new Break();

    case '{':
    return block();

    default:
    return assign();
    }
    }

    Stmt assign() throws IOException {
    Stmt stmt;
    Token t = look;
    match(Tag.ID);
    Id id = top.get(t);
    if (id == null)
    error(t.toString() + " undeclared");

    if (look.tag == '=') { // S -> id = E ;
    move();
    stmt = new Set(id, bool());
    } else { // S -> L = E ;
    Access x = offset(id);
    match('=');
    stmt = new SetElem(x, bool());
    }
    match(';');
    return stmt;
    }

    Expr bool() throws IOException {
    Expr x = join();
    while (look.tag == Tag.OR) {
    Token tok = look;
    move();
    x = new Or(tok, x, join());
    }
    return x;
    }

    Expr join() throws IOException {
    Expr x = equality();
    while (look.tag == Tag.AND) {
    Token tok = look;
    move();
    x = new And(tok, x, equality());
    }
    return x;
    }

    Expr equality() throws IOException {
    Expr x = rel();
    while (look.tag == Tag.EQ || look.tag == Tag.NE) {
    Token tok = look;
    move();
    x = new Rel(tok, x, rel());
    }
    return x;
    }

    Expr rel() throws IOException {
    Expr x = expr();
    switch (look.tag) {
    case '<':
    case Tag.LE:
    case Tag.GE:
    case '>':
    Token tok = look;
    move();
    return new Rel(tok, x, expr());
    default:
    return x;
    }
    }

    Expr expr() throws IOException {
    Expr x = term();
    while (look.tag == '+' || look.tag == '-') {
    Token tok = look;
    move();
    x = new Arith(tok, x, term());
    }
    return x;
    }

    Expr term() throws IOException {
    Expr x = unary();
    while (look.tag == '*' || look.tag == '/') {
    Token tok = look;
    move();
    x = new Arith(tok, x, unary());
    }
    return x;
    }

    Expr unary() throws IOException {
    if (look.tag == '-') {
    move();
    return new Unary(Word.minus, unary());
    } else if (look.tag == '!') {
    Token tok = look;
    move();
    return new Not(tok, unary());
    } else
    return factor();
    }

    Expr factor() throws IOException {
    Expr x = null;
    switch (look.tag) {
    case '(':
    move();
    x = bool();
    match(')');
    return x;
    case Tag.NUM:
    x = new Constant(look, Type.Int);
    move();
    return x;
    case Tag.REAL:
    x = new Constant(look, Type.Float);
    move();
    return x;
    case Tag.TRUE:
    x = Constant.True;
    move();
    return x;
    case Tag.FALSE:
    x = Constant.False;
    move();
    return x;
    default:
    error("syntax error");
    return x;
    case Tag.ID:
    String s = look.toString();
    Id id = top.get(look);
    if (id == null)
    error(look.toString() + " undeclared");
    move();
    if (look.tag != '[')
    return id;
    else
    return offset(id);
    }
    }

    Access offset(Id a) throws IOException { // I -> [E] | [E] I
    Expr i;
    Expr w;
    Expr t1, t2;
    Expr loc; // inherit id

    Type type = a.type;
    match('[');
    i = bool();
    match(']'); // first index, I -> [ E ]
    type = ((Array) type).of;
    w = new Constant(type.width);
    t1 = new Arith(new Token('*'), i, w);
    loc = t1;
    while (look.tag == '[') { // multi-dimensional I -> [ E ] I
    match('[');
    i = bool();
    match(']');
    type = ((Array) type).of;
    w = new Constant(type.width);
    t1 = new Arith(new Token('*'), i, w);
    t2 = new Arith(new Token('+'), loc, t1);
    loc = t2;
    }

    return new Access(a, loc, type);
    }
    }
    this is where i got this exception on line 24

    this is error screen How to Fix dispatchUncaughtException in Java-eclipse.png

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default Re: How to Fix dispatchUncaughtException in Java

    Quote Originally Posted by jasjeet View Post
    package parser;
    import java.io.*;
    import lexer.*;
    import symbols.*;
    import inter.*;

    [ ... ]
    this is where i got this exception on line 24

    this is error screen
    That came from one of the classes you imported (and used); I bet that code came with documentation; read it, because this exception is not from the standard classes; we can't help you any further with this.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to Fix dispatchUncaughtException in Java

    The class you posted isn't even the one that's shown in the debugger. The exception is being thrown in main.Main. The debugger has suspended execution, but if you click the run icon on the toolbar, it'll continue to run and the default UncaughtExceptionHandler will print the stack trace. The information in the stack trace will tell you exactly what and where the problem is.
    Get in the habit of using standard Java naming conventions!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •