How can I make an Ada Exception visible outside a module? - exception

I don't understand why I'm getting an error on this Ada exception. I'm getting this error for the following example:
Builder results: "Send_Command_Failed" is not visible (more references follow) 1085:12
It appears that I need to declare the exception in sample_client.ads, then the code compiles but I just find that approach to be un-modular and counter-intuitive. So the question is really how can I do this "right" and export from the command_interface module.
Example client like ...
-- sample_client.adb --
:
with command_interface;
:
package body sample_client is
procedure example is
begin
: ... stuff
exception
when Send_Command_Failed =>
Trace_Error( "Send Exception: Send_Command_Failed at example");
raise;
end example;
end sample_client;
for a library interface here:
-- command_interface.ads --
package command_interface
:
exception Send_Command_Failed;
:
end command_interface;
some code in Body can throw the Send_Command_Failed exception ...
-- command_interface.adb --
package body command_interface
: ... code raises: Send_Command_Failed
:
end Command_Interface; -- specification
package body command_interface
: ... code raises: Send_Command_Failed
:
end Command_Interface; -- specification

Have you tried to tell the compiler where to find the exception declaration?
exception
when command_interface.Send_Command_Failed =>
?

Related

Catch the exception in the lexer in Antlr3

How to catch the exception in the lexer? In parser if a rule is failed (or mismatched with the given input stream ) Antlr will throw the exception and we can easily catch this exception.Catch the exception in the lexer in Antlr3.Ref:Error handeling in antlr 3.0...
attribute :
Value1 integer1["Value1"] { System.out.println("Accepted"); }
| Value2 integer2["Value2"] { System.out.println("Accepted"); }
;
catch[Exception e] {System.out.println("General error Reported");}
It will work in parser.But how can I catch the exception in the lexer itself?.Say in parser I am having the rule like
str:STRING|DIGIT;
and in lexer STRING is defined as
STRING : ('"' 'a'..'z' '"');
My input stream is "God"....If I miss the double quote or if I put the extra double quote then I want that exception should be caught in the lexer itself...Is there any method to do this? Is it possible?
Override one or more of the following methods to use ANTLR's own exception handling (this applies to both lexer and parser) - note that this applies only to exceptions caused by input mismatch:
emitErrorMessage() - to handle how the message is displayed to user
getErrorHeader() - to change how error message header is created
getErrorMessage() - to change how the description of error is created
displayRecognitionError() - to change how the message is created from the exception, or to completely change how the exception is handled
The key difference between ANTLR's lexer and parser is that in lexer, there is no start rule or "current" rule - the lexer tries to match all available rules in parallel. So if a mismatch occurs, it cannot be attributed to any particular rule (so it also cannot be handled in any particular rule using a catch block).

Why do I get Error #2004 while passing two strings to a function in AS3?

My Function's definition :
public function updateTextField(value:String, label:String):void{
.....
}
I call it as below :
updateTextField("Level : 1 Passed","L1");
And I get below error while debugging it using FDB, and the function's content isn't updated ( Textfield isn't updated ) :
"[Fault] exception, information=ArgumentError: Error #2004: One of the parameters is invalid."
As far as I can understand, my function expects two strings, and that's why I provide it with.
.
I added a try-catch block when I call the function.
try{
updateTextField("Level : 1 Passed","L1");
} catch(e1:ArgumentError) {
trace("1. " + e1);
}
Now , though it throws exception, but before that the function gets executed successfully. Though, it solves my problem up to an extent (except I will have to call the function inside try-catch every time)
But I would like to understand why I get such error when correct arguments are bring passed, and how could I rectify it ?

How to debug Mockolate for unit testing

While unit testing in actionscript-3 with mockolate I have run into quite a few problems/errors:
Error: No Expectation defined for Invocation:[FloxyInvocation invocationType=GETTER name="propertyName" arguments=[]]
Error: 1 unmet Expectation
Mockolate errors and debugging are poorly documented and searches bring up no results, so solving these problems get very tricky.
No expectation defined error is thrown when the function you are testing expects the specified invocation type and name:
Error: No Expectation defined for Invocation:[FloxyInvocation invocationType=GETTER name="propertyName" arguments=[]]
Can be solved with:
mock(object).getter("propertyName").returns(someValue);
Unmet expectation error can be thrown when you created a mock statement (a getter or setter) but there is no getter or setter defined for the variable you are getting or setting.
Error: 1 unmet Expectation
Can be solved with:
public function get variable():String {
return _variable;
}
public function set variable(value:String):void {
_variable = value;
}

Also log every exception at error level

Using Groovy / Grails and log4j is there any way to ensure every exception thrown in the code is logged at error level.
Rather than having to find every catch block and explictly log it?
If not groovy / grails - a java suggestion will suffice.
Thanks
I don't believe there's any way to do this for handled exceptions, but you can do it for unhandled exceptions by adding the following to UrlMappings.groovy
"500"(controller: 'error')
Then create an ErrorController.groovy under grails-app/controllers
class ErrorController {
def index() {
Throwable exception = request?.exception?.cause
log.error 'something bad happened', exception
}
}

Type mismatch while using allCatch opt

In order to avoid Java exceptions I'm using Scala's exception handling class.
However, when compiling the following snippet:
import scala.util.control.Exception._
val cls = classManifest[T].erasure
// Invoke special constructor if it's available. Otherwise use default constructor.
allCatch opt cls.getConstructor(classOf[Project]) match {
case Some(con) =>
con.newInstance(project) // use constructor with one Project param
case None =>
cls.newInstance // just use default constructor
};
I receive the following error:
error: type mismatch;
[scalac] found : java.lang.reflect.Constructor[_]
[scalac] required: java.lang.reflect.Constructor[_$1(in method init)] where
type _$1(in method init)
[scalac] allCatch opt cls.getConstructor(classOf[Project]) match {
[scalac] ^
[scalac] one error found
What's going on here and how can I fix it?
I have no explanation, but a much shorter example which I hope pinpoint where the problem occurs. I think it is not related at all to exceptions, nor to reflection. Whether this behavior is an arcane but correct consequence of the specification or a bug, I have no idea.
val untypedList : List[_] = List("a", "b")
val typedList : List[String] = List("a", "b")
def uselessByName[A](a: => A) = a
def uselessByValue[A](a: A) = a
uselessByName(untypedList) fails with the same error as your code. The other combinations do not. So combination of a method with a generic call-by-name argument, called with a parameter of a generic with an existential type.
uselessByName[List[_]](untypedList) works, so I guess if you call explicitly opt[Constructor[_]] it might work too.
The type inference scheme has gotten confused by the types available--specifically, by the type of cls. If we write generic code:
def clser[A](cls: Class[A]) = allCatch opt cls.getConstructor(classOf[Project])
then it works perfectly okay. But you're probably doing something else--I can't tell what because you didn't provide the code--and this results in a mismatch between the expected and actual types.
My currently solution is to cast the constructor explicitly.
cls.getConstructor(classOf[Project]) becomes cls.getConstructor(classOf[Project]).asInstanceOf[Constructor[Project]].
I'm still wondering about the actual error and if there are better ways to resolve it -- so I'm going to leave this open.